[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-08-03 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Hi folks,

I found an issue with building Android using this patch. I've reduced it down 
to the following problem where the evaluation of the `std::visit` is believed 
to be non-exhaustive, but it seems like it is? Would you mind taking a look? 
Admittedly, my knowledge in this area of the cxx stdlib is not so great.

Thanks.

  $ cat /tmp/variant.cpp
  #include 
  #include 
  
  struct A {};
  struct B {};
  
  using MyVariant = std::variant;
  
  // Helper to std::visit with lambdas.
  template 
  struct Visitor : V... {};
  // explicit deduction guide (not needed as of C++20)
  template 
  Visitor(V...) -> Visitor;
  
  const char* toString(const MyVariant& args) {
  Visitor toStringVisitor{
  [&](const A&) { return "A"; },
  [&](const B&) { return "B"; },
  };
  return std::visit(toStringVisitor, args);
  }



  $ ~/llvm-build/opt/bin/clang++ /tmp/variant.cpp -c -o /tmp/variant.o 
-std=c++17 -stdlib=libc++
  In file included from /tmp/variant.cpp:2:
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:680:19:
 error: static assertion failed due to requirement 
'is_invocable_v &, const A &>': `std::visit` requires the visitor to 
be exhaustive.
680 | static_assert(is_invocable_v<_Visitor, _Values...>,
|   ^~~~
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:689:7:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__variant::__std_visit_exhaustive_visitor_check &, const A &>' 
requested here
689 |   __std_visit_exhaustive_visitor_check<
|   ^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__type_traits/invoke.h:337:10:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__variant::__value_visitor 
&>::operator() &>' requested here
337 | decltype(std::declval<_Fp>()(std::declval<_Args>()...))
|  ^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:572:16:
 note: while substituting deduced template arguments into function template 
'__invoke' [with _Fp = 
std::__variant_detail::__visitation::__variant::__value_visitor &>, _Args = 
 &>]
572 | return _VSTD::__invoke(
|^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__config:805:17:
 note: expanded from macro '_VSTD'
805 | #  define _VSTD std
| ^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:581:43:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__base::__dispatcher<0>::__dispatch &> &&, const 
std::__variant_detail::__base &>' requested here
581 | return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>;
|   ^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:608:12:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__base::__make_dispatch &> &&, const 
std::__variant_detail::__base &, 0UL>' requested here
608 | return __make_dispatch<_Fp, _Vs...>(__is);
|^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:616:34:
 note: (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to 
see all)
616 | return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>(
|  ^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:533:9:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__base::__make_fmatrix &> &&, const 
std::__variant_detail::__base &>' requested here
533 | __make_fmatrix<_Visitor&&,
| ^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:642:20:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__base::__visit_alt &>, const 
std::__variant_detail::__impl &>' requested here
642 | return __base::__visit_alt(
|^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:661:12:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__variant::__visit_alt &>, const 
std::variant &>' requested here
661 | return __visit_alt(
|^
  
/usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:1759:21:
 note: in instantiation of function template specialization 
'std::__variant_detail::__visitation::__variant::__visit_value &, const 
std::variant &>' requested here
   1759 |   return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor),
| ^

[PATCH] D146987: [Assignment Tracking] Enable by default

2023-05-26 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Hey, found another error that looks to be different from @maskray's revert.

  $ bin/clang -c -O2 -g -ftrivial-auto-var-init=zero /tmp/repro.c


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146987/new/

https://reviews.llvm.org/D146987

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126959: [C++20][Modules] Introduce an implementation module.

2023-03-27 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Hi, yep, I've reverted upstream. If you could please also integrate 
https://reviews.llvm.org/rG8c7c1f11ffaacf762e612c65440fd2cbb58ee426 in the 
relanding, that would be great.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126959/new/

https://reviews.llvm.org/D126959

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139395: Add CFI integer types normalization

2023-02-02 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Hey folks, looks like this caused a failure on the msan buildbot: 
https://lab.llvm.org/buildbot/#/builders/237/builds/785

It's been had a long-running bug that I'm still tracking down but seems like 
this is a new failure caused by this patch. The track-origins log is copied 
below for your convenience.

The bot can be reproduced by following the instructions at 
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild, you'd 
want to substitute `buildbot_fast.sh` for `buildbot_bootstrap_msan.sh` though. 
Given the bot is already red when this was committed, please ignore any 
failures other than this one.

  ==3442210==WARNING: MemorySanitizer: use-of-uninitialized-value
  #0 0xf388495c in (anonymous 
namespace)::CXXNameMangler::mangleUnqualifiedName(clang::GlobalDecl, 
clang::DeclarationName, clang::DeclContext const*, unsigned int, 
llvm::SmallVector const*) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:1631:9
  #1 0xf389ab8c in mangleUnqualifiedName 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:501:5
  #2 0xf389ab8c in (anonymous 
namespace)::CXXNameMangler::mangleNestedName(clang::GlobalDecl, 
clang::DeclContext const*, llvm::SmallVector const*, bool) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:1735:5
  #3 0xf3847b20 in (anonymous 
namespace)::CXXNameMangler::mangleFunctionEncoding(clang::GlobalDecl) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:811:5
  #4 0xf38985fc in (anonymous 
namespace)::CXXNameMangler::mangleLocalName(clang::GlobalDecl, 
llvm::SmallVector const*) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:1806:7
  #5 0xf3897d00 in (anonymous 
namespace)::CXXNameMangler::mangleType(clang::TagType const*) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:3468:3
  #6 0xf384e184 in (anonymous 
namespace)::CXXNameMangler::mangleType(clang::QualType) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp
  #7 0xf384106c in (anonymous 
namespace)::ItaniumMangleContextImpl::mangleCXXRTTIName(clang::QualType, 
llvm::raw_ostream&, bool) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/AST/ItaniumMangle.cpp:6626:11
  #8 0xeb77c768 in 
clang::CodeGen::CodeGenTBAA::getBaseTypeInfoHelper(clang::Type const*) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CodeGenTBAA.cpp:394:16
  #9 0xeb777978 in getBaseTypeInfo 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CodeGenTBAA.cpp:427:28
  #10 0xeb777978 in 
clang::CodeGen::CodeGenTBAA::getTypeInfo(clang::QualType) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CodeGenTBAA.cpp:242:12
  #11 0xeb779184 in 
clang::CodeGen::CodeGenTBAA::getAccessInfo(clang::QualType) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CodeGenTBAA.cpp:265:25
  #12 0xeb0c2cfc in MakeAddrLValue 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CodeGenFunction.h:2494:33
  #13 0xeb0c2cfc in (anonymous 
namespace)::AggExprEmitter::VisitLambdaExpr(clang::LambdaExpr*) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CGExprAgg.cpp:1350:23
  #14 0xeb0ab220 in Visit 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CGExprAgg.cpp:108:34
  #15 0xeb0ab220 in 
clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, 
clang::CodeGen::AggValueSlot) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CGExprAgg.cpp:2038:49
  #16 0xea90e15c in 
clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, 
clang::CodeGen::AggValueSlot, bool) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CGExpr.cpp:224:5
  #17 0xea910c80 in 
clang::CodeGen::CodeGenFunction::EmitAnyExprToTemp(clang::Expr const*) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CGExpr.cpp:237:10
  #18 0xeac28f4c in 
clang::CodeGen::CodeGenFunction::EmitCallArg(clang::CodeGen::CallArgList&, 
clang::Expr const*, clang::QualType) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CGCall.cpp:4461:12
  #19 0xeac25c34 in 
clang::CodeGen::CodeGenFunction::EmitCallArgs(clang::CodeGen::CallArgList&, 
clang::CodeGen::CodeGenFunction::PrototypeWrapper, 
llvm::iterator_range>, 
clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int, 
clang::CodeGen::CodeGenFunction::EvaluationOrder) 
/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/clang/lib/CodeGen/CGCa

[PATCH] D142826: [Clang] Add -Wtype-limits to -Wextra for GCC compatibility

2023-02-01 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Hey, looks like this broke the x86_64-linux sanitizer buildbot: 
https://lab.llvm.org/buildbot/#/builders/37/builds/19910

You can reproduce the bot using the instructions at 
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild 
(substitute `buildbot_fast.sh` for `buildbot_cmake.sh` to get the right one, 
but I don't think using the official buildscript is necessary. This looks like 
a 2-stage compile is not currently `-Wextra -Werror` clean:

  
/b/sanitizer-x86_64-linux/build/llvm-project/llvm/lib/ProfileData/InstrProfReader.cpp:177:41:
 error: result of comparison 'uint64_t' (aka 'unsigned long') > 
18446744073709551615 is always false [-Werror,-Wtautological-type-limit-compare]
if (uint64_t(Buffer->getBufferSize()) > 
std::numeric_limits::max())
~ ^ 
  
/b/sanitizer-x86_64-linux/build/llvm-project/llvm/lib/ProfileData/InstrProfReader.cpp:227:41:
 error: result of comparison 'uint64_t' (aka 'unsigned long') > 
18446744073709551615 is always false [-Werror,-Wtautological-type-limit-compare]
if (uint64_t(Buffer->getBufferSize()) > 
std::numeric_limits::max())
~ ^ 

I tried to whack-a-mole those two bugs (see my two commits on 
https://lab.llvm.org/buildbot/#/builders/37/builds/19926), but there's more 
latent bugs hanging around.

Probably worth reverting this and the warnings need to be fixed inside 
clang/llvm first, then we can make it the default.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142826/new/

https://reviews.llvm.org/D142826

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2023-01-31 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D133392#4094524 , @dyung wrote:

> Hi @hctim, the test you added is failing on buildbots where AArch64 is not 
> built, can you either update the test to not require that backend, or mark 
> the test as requiring it?
>
> https://lab.llvm.org/buildbot/#/builders/139/builds/35253
>
>   error: unable to create target: 'No available targets are compatible with 
> triple "aarch64-unknown-linux-android31"'
>   1 error generated.

Thanks for the heads up. I've reverted and will test on my end before relanding.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2023-01-31 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4edfcff71e15: [MTE] Add AArch64GlobalsTagging Pass (authored 
by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -70,6 +70,7 @@
 ; CHECK-NEXT:   Lazy Block Frequency Analysis
 ; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Optimize selects
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -26,6 +26,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   SME ABI Pass
 ; CHECK-NEXT:   Exception handling preparation
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -238,6 +238,7 @@
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
   initializeAArch64DAGToDAGISelPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -587,6 +588,7 @@
   if (getOptLevel() == CodeGenOpt::Aggressive && EnableSelectOpt)
 addPass(createSelectOptimizePass());
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -363,6 +363,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass()) {
   if (isWindowsArm64EC() && GV->getValueType()->isFunctionTy())
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,142 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGran

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2023-01-31 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 493642.
hctim marked 2 inline comments as done.
hctim added a comment.

Rebase for submit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -70,6 +70,7 @@
 ; CHECK-NEXT:   Lazy Block Frequency Analysis
 ; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Optimize selects
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -26,6 +26,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   SME ABI Pass
 ; CHECK-NEXT:   Exception handling preparation
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -238,6 +238,7 @@
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
   initializeAArch64DAGToDAGISelPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -587,6 +588,7 @@
   if (getOptLevel() == CodeGenOpt::Aggressive && EnableSelectOpt)
 addPass(createSelectOptimizePass());
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -363,6 +363,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass()) {
   if (isWindowsArm64EC() && GV->getValueType()->isFunctionTy())
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,142 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+static bool shouldTagGlobal(GlobalVariable &G) {
+  if (!G.isTagged())

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2023-01-03 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 486093.
hctim added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -70,6 +70,7 @@
 ; CHECK-NEXT:   Lazy Block Frequency Analysis
 ; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Optimize selects
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -26,6 +26,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   SME ABI Pass
 ; CHECK-NEXT:   Exception handling preparation
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -238,6 +238,7 @@
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
   initializeAArch64DAGToDAGISelPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -587,6 +588,7 @@
   if (getOptLevel() == CodeGenOpt::Aggressive && EnableSelectOpt)
 addPass(createSelectOptimizePass());
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -353,6 +353,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass()) {
   if (isWindowsArm64EC() && GV->getValueType()->isFunctionTy())
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,144 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+static bool shouldTagGlobal(GlobalVariable &G) {
+  if (!G.isTagged())
+return false;
+
+  assert(G.hasSanitizerMetad

[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-22 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4012854 , @ilinpv wrote:

> I don't think `std::equal` is underlying cause here. We have 
> featuresStrs_size() comparison before calling it:
>
>   if (CurClones && NewClones &&
> (CurClones->featuresStrs_size() != NewClones->featuresStrs_size() 
> ||
>  !std::equal(CurClones->featuresStrs_begin(),
>  CurClones->featuresStrs_end(),
>  NewClones->featuresStrs_begin( {
>
> Also even if we completely remove std::equal the use-of-uninitialized-value 
> error still persist.

Sorry for the red herring. MSan is detecting use-after-destructor here.

`Strings` holds `StringRef`-references to the memory allocated in 
`StringsBuffer`.

When StringsBuffer is template-constructed with two inline elements (i.e. 
`SmallVector, 2> StringsBuffer;`), the third element that gets 
added (in `clang::Sema::checkTargetClonesAttrString`, `SemaDeclAttr.cpp:3568`) 
causes the `SmallVector` to move the three strings to the heap (the two already 
existing inline and the new addition).

`SmallVector` cleans up the inline memory by calling the destructors on it. 
MSan dutifully marks the destroyed memory as uninitialized, to detect 
use-after-destruction. The reason why ASan doesn't generate a report here is 
that the memory is still technically "reachable", it's possible to have 
destroyed memory that's still part of a live stack frame or hasn't had its heap 
allocation cleaned up yet.

Because `Strings` captured the reference of the two string objects when they 
were inline-allocated, as soon as this move-to-heap happens, these two 
references are dangling. Then, when any caller attempts to iterate over 
`Strings`, it finally explodes as MSan correctly detects the use of destroyed 
memory.

Allocating 3 objects inline solves the issue for now, as there's no uses that 
end up needing more than 3 elements, but this leaves a footgun for anyone who 
would add another element later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127812/new/

https://reviews.llvm.org/D127812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4012276 , @ilinpv wrote:

> I've managed to reproduce "MemorySanitizer: use-of-uninitialized-value" error 
> locally, thank you @hctim for help!
> If I understand it right, it seems **MSan didn't handle correctly 
> SmallVector** - a variable-sized array with some number of elements in-place 
> and heap allocation for additional elements if needed:
>
>   clang/lib/Sema/SemaDeclAttr.cpp:3615 SmallVector, 2> 
> StringsBuffer;
>
> There were 2 elements in-placed for StringsBuffer and tests which require 3 
> failed with MSan use-of-uninitialized-value error. 
> With number of StringsBuffer in-placed elements set to 3
>
>   SmallVector, 3> StringsBuffer;
>
> all use-of-uninitialized-value errors have gone.

I'm not sure "MSan didn't handle correctly SmallVector" is the case. Given your 
diagnosis of 3-elements-vs-2, I'm guessing the root cause is that 
`clang/lib/Sema/SemaDecl.cpp:11369` is wrong:

  !std::equal(CurClones->featuresStrs_begin(),
  CurClones->featuresStrs_end(),
  NewClones->featuresStrs_begin( {

This construction of `std::equal` is very error-prone, as if `NewClones.size() 
< CurClones.size()`, then this invariable leads to buffer-overflow. I'm 
wondering if that's the underlying cause, it would seem entirely possible that 
expanding the in-place elements are always "initialized" from MSan's 
perspective and so the current code has a false-negative, and your new code 
made it so that the vector is now heap-based, which is revealing the underlying 
issue. Maybe worth trying one more thing and adding an 
`assert(CurClones->size() <= NewClones->size());` to double check?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127812/new/

https://reviews.llvm.org/D127812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4011372 , @ilinpv wrote:

> Regular builds works fine for me, pthreads located here 
> "/lib/x86_64-linux-gnu/libpthread.so" 
> "/usr/lib/x86_64-linux-gnu/libpthread.so". Enabling 
> "-DLLVM_USE_SANITIZER=Memory" resulted in many "WARNING: MemorySanitizer: 
> use-of-uninitialized-value" on tblgen like:
>
>   cd /data/ReleasesToCommit/llvm-project/build && 
> /data/ReleasesToCommit/llvm-project/build/bin/llvm-tblgen 
> -gen-intrinsic-enums -intrinsic-prefix=s390 -I 
> /data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR 
> -I/data/ReleasesToCommit/llvm-project/build/include 
> -I/data/ReleasesToCommit/llvm-project/llvm/include 
> /data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR/Intrinsics.td 
> --write-if-changed -o include/llvm/IR/IntrinsicsS390.h -d 
> include/llvm/IR/IntrinsicsS390.h.d
>   [build] ==2441251==WARNING: MemorySanitizer: use-of-uninitialized-value

Yeah that's a false-positive because of bad-ordering. MSan is much tricker 
because it requires an instrumented libcxx. If you can't use the buildscript, 
an MVP for the right ordering should be something like:

1. Build a new clang.

  $ cd /tmp/1/
  $ cmake \
  -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld" \
  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
  -DCMAKE_C_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++ \
  -GNinja \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_USE_LINKER=lld \
  -DCMAKE_C_FLAGS="-Wall" \
  -DCMAKE_CXX_FLAGS="-Wall" \
  /path/to/llvm/llvm
  $ ninja clang lld compiler-rt llvm-symbolizer



2. Build a sanitizer libcxx.

  $ cd /tmp/2
  $ cmake \
  -DCMAKE_C_COMPILER=/tmp/1/bin/clang \
  -DCMAKE_CXX_COMPILER=/tmp/1/bin/clang++ \
  -GNinja \
  -DLLVM_USE_SANITIZER=Memory \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DLLVM_ENABLE_RUNTIMES="'libcxx;libcxxabi'" \
  -DLLVM_USE_LINKER="'lld'" \
  /path/to/llvm/runtimes/ # < Make sure this is *runtimes*, not llvm.
  $ ninja cxx cxxabi



3. Build a msan-ified clang, and use the libcxx from step 2.

  $ cd /tmp/3
  $ cat .cmake_script.sh
  #!/bin/bash -e
  
  LDFLAGS="-lc++abi"
  LDFLAGS="$LDFLAGS -Wl,--rpath=/tmp/2/lib" # < use the instrumented libcxx 
from step 2
  LDFLAGS="$LDFLAGS -L/tmp/2/lib"
  
  CFLAGS="$LDFLAGS"
  CFLAGS="$CFLAGS -fsanitize=memory"
  CFLAGS="$CFLAGS -nostdinc++"
  CFLAGS="$CFLAGS -isystem /tmp/2/include" # < use the instrumented libcxx 
from step 2
  CFLAGS="$CFLAGS -isystem /tmp/2/include/c++/v1"
  CFLAGS="$CFLAGS -w"
  CFLAGS="$CFLAGS -fsanitize-memory-use-after-dtor 
-fsanitize-memory-param-retval"
  
  USE_SANITIZER="Memory"
  # USE_SANITIZER="MemoryWithOrigins"  # <---+-- uncomment 
these and comment the USE_SANITIZER="Memory" above to get track-origins.
  # CFLAGS="$CFLAGS -fsanitize-memory-track-origins=2"  # <--+
  
  cmake \
  -DCMAKE_C_COMPILER=/tmp/1/bin/clang \
  -DCMAKE_CXX_COMPILER=/tmp/1/bin/clang++ \
  -DLLVM_ENABLE_LIBCXX=ON \
  -GNinja \
  -DLLVM_USE_SANITIZER="$USE_SANITIZER" \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DCMAKE_C_FLAGS="$CFLAGS" \
  -DCMAKE_CXX_FLAGS="$CFLAGS" \
  -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \
  -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \
  -DLLVM_USE_LINKER="lld" \
  /path/to/llvm/llvm
  $ . .cmake_script.sh
  $ ninja clang lld
  $ ninja check-clang check-llvm # <- finally, run your tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127812/new/

https://reviews.llvm.org/D127812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4010856 , @ilinpv wrote:

> It would be great to have more details how to setup up your bot, using 
> buildbot_fast.sh on x86_64 Ubuntu 22.04 LTS leads to error ( pthreads 
> installed ):
>
>   CMake Error at 
> /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 
> (message):
> Could NOT find Threads (missing: Threads_FOUND)
>   Call Stack (most recent call first):
> /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 
> (_FPHSA_FAILURE_MESSAGE)
> /usr/share/cmake-3.22/Modules/FindThreads.cmake:238 
> (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
> cmake/config-ix.cmake:114 (find_package)
> CMakeLists.txt:776 (include)
>
> Also MemorySanitizer: use-of-uninitialized-value cases from 
> https://lab.llvm.org/buildbot/#/builders/5/builds/30139 looks fine locally, 
> all values initialized, could MSAN produce false positive results?

MSan can find false positives, but that's only if code ends up in your binary 
that isn't built with MSan. The buildscripts are written so that everything 
gets instrumented.

Hmm, not exactly sure what's going on with the `could NOT find Threads` there. 
A quick googling seems to point to pthreads.so not being in the right places, 
but I don't think the buildbot does anything special. Do your regular builds 
with `-DLLVM_ENABLE_PROJECTS="compiler_rt;clang;lld"` work?

When you say that it looks fine locally, is that from your own checkout but 
using `-DLLVM_USE_SANITIZER=Memory`? First thing to check is that you do end up 
with MSan in the test (in particular the clang binary that's being produced), 
which you can do by `nm bin/clang-16 | grep __msan_init`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127812/new/

https://reviews.llvm.org/D127812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-20 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4009447 , @hctim wrote:

> Hi, this looks like a candidate for breaking the MSan bot: 
> https://lab.llvm.org/buildbot/#/builders/5/builds/30139
>
> Still looking into it and bisecting, will let you know when I have more info. 
> To reproduce the bots, the best way (because MSan setup is tricky because it 
> requires an instrumented libcxx) is to use the scripts from 
> https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild 
> (buildbot_fast.sh is the right one).

Yeah, unfortunately I did track this failure down to this commit and reverted 
it upstream. If you need help figuring it out, please let me know. You may find 
that adding `-fsanitize-memory-track-origins=2` useful to add to the 
buildscript as well (which can be done by changing `check_stage2_msan` to 
`check_stage2_msan_track_origins` in `buildbot_fast.sh`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127812/new/

https://reviews.llvm.org/D127812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-20 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Hi, this looks like a candidate for breaking the MSan bot: 
https://lab.llvm.org/buildbot/#/builders/5/builds/30139

Still looking into it and bisecting, will let you know when I have more info. 
To reproduce the bots, the best way (because MSan setup is tricky because it 
requires an instrumented libcxx) is to use the scripts from 
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild 
(buildbot_fast.sh is the right one).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127812/new/

https://reviews.llvm.org/D127812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2022-12-12 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.
Herald added subscribers: Enna1, abrachet, MaskRay.
Herald added a project: All.

Partially merged (making -fsanitize=scudo use scudo_standalone) merged in 
D138157 . Will probably re-use this in a bit 
to add the dangling scudo tests to scudo_standlaone, but abandoning this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102543/new/

https://reviews.llvm.org/D102543

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-12-02 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc414bbefe45a: Make -fsanitize=scudo use scudo_standalone. 
Delete check-scudo. (authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138157/new/

https://reviews.llvm.org/D138157

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/CMakeLists.txt
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  llvm/docs/GwpAsan.rst

Index: llvm/docs/GwpAsan.rst
===
--- llvm/docs/GwpAsan.rst
+++ llvm/docs/GwpAsan.rst
@@ -143,9 +143,10 @@
   default visibility. This will override the compile time define;
 
 - Depending on allocator support (Scudo has support for this mechanism): Through
-  the environment variable ``GWP_ASAN_OPTIONS``, containing the options string
-  to be parsed. Options defined this way will override any definition made
-  through ``__gwp_asan_default_options``.
+  an environment variable, containing the options string to be parsed. In Scudo,
+  this is through `SCUDO_OPTIONS=GWP_ASAN_${OPTION_NAME}=${VALUE}` (e.g.
+  `SCUDO_OPTIONS=GWP_ASAN_SampleRate=100`). Options defined this way will
+  override any definition made through ``__gwp_asan_default_options``.
 
 The options string follows a syntax similar to ASan, where distinct options
 can be assigned in the same string, separated by colons.
@@ -216,9 +217,9 @@
 
 .. code:: console
 
-  $ clang++ -fsanitize=scudo -std=c++17 -g buggy_code.cpp
-  $ for i in `seq 1 200`; do
-  GWP_ASAN_OPTIONS="SampleRate=100" ./a.out > /dev/null;
+  $ clang++ -fsanitize=scudo -g buggy_code.cpp
+  $ for i in `seq 1 500`; do
+  SCUDO_OPTIONS="GWP_ASAN_SampleRate=100" ./a.out > /dev/null;
 done
   |
   | *** GWP-ASan detected a memory error ***
Index: compiler-rt/test/scudo/standalone/CMakeLists.txt
===
--- compiler-rt/test/scudo/standalone/CMakeLists.txt
+++ compiler-rt/test/scudo/standalone/CMakeLists.txt
@@ -10,12 +10,12 @@
   ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan/lit.site.cfg.py)
 list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan)
   endif()
-endif()
 
-add_lit_testsuite(check-scudo_standalone
-  "Running Scudo Standalone tests"
-  ${SCUDO_STANDALONE_TESTSUITES}
-  DEPENDS ${SCUDO_STANDALONE_TEST_DEPS})
+  add_lit_testsuite(check-scudo_standalone
+"Running Scudo Standalone tests"
+${SCUDO_STANDALONE_TESTSUITES}
+DEPENDS ${SCUDO_STANDALONE_TEST_DEPS})
 
-set_target_properties(check-scudo_standalone
-  PROPERTIES FOLDER "Compiler-RT Tests")
+  set_target_properties(check-scudo_standalone
+PROPERTIES FOLDER "Compiler-RT Tests")
+endif()
Index: compiler-rt/test/scudo/CMakeLists.txt
===
--- compiler-rt/test/scudo/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-set(SCUDO_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-set(SCUDO_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
-
-set(SCUDO_TESTSUITES)
-
-set(SCUDO_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(NOT COMPILER_RT_STANDALONE_BUILD)
-  list(APPEND SCUDO_TEST_DEPS scudo)
-endif()
-
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
-  )
-
-set(SCUDO_TEST_ARCH ${SCUDO_SUPPORTED_ARCH})
-foreach(arch ${SCUDO_TEST_ARCH})
-  set(SCUDO_TEST_TARGET_ARCH ${arch})
-  string(TOLOWER "-${arch}" SCUDO_TEST_CONFIG_SUFFIX)
-  get_test_cc_for_arch(${arch} SCUDO_TEST_TARGET_CC SCUDO_TEST_TARGET_CFLAGS)
-  string(TOUPPER ${arch} ARCH_UPPER_CASE)
-  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-
-  configure_lit_site_cfg(
-${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
-  list(APPEND SCUDO_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
-endforeach()
-
-add_subdirectory(standalone)
-
-add_lit_testsuite(check-scudo "Running the Scudo Hardened Allocator tests"
-  ${SCUDO_TESTSUITES}
-  DEPENDS ${SCUDO_TEST_DEPS})
-set_target_properties(check-scudo PROPERTIES FOLDER "Compiler-RT Misc")
Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/CMakeLists.txt
+++ compiler-rt/test/CMakeLists.txt
@@ -50,7 +50,11 @@
 function(compiler_rt_test_runtime runtime)
   string(TOUPPER ${runtime} runtime_uppercase)
   if(COMPILER_RT_HAS_${runtime_uppercase})
-add_subdirectory(${runtime})
+if (${runtime} STREQUAL scudo_standalone)
+  add_subdirectory(scudo/standalone)
+else()
+  add_subdirectory(${runtime})
+endif()
 foreach(directory ${ARGN})
   add

[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-12-02 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 479693.
hctim added a comment.

Lots of places in scudo_standalone depend on GWP-ASan, and it seems far more 
reasonable to make COMPILER_RT_HAS_GWP_ASAN mean "is GWP-ASan actually going to 
be built", rather than checking three variables in all the places.

Give the same treatment to COMPILER_RT_HAS_SCUDO_STANDALONE.

This should fix the reviewer problems that were identified:

1. scudo_standalone's cmake rules don't get generated when 
COMPILER_RT_BUILD_SANITIZERS=Off or COMPILER_RT_SANITIZERS_TO_BUILD does not 
contain scudo_standalone.
2. check-scudo_standalone's cmake rules don't get generated when 
COMPILER_RT_INCLUDE_TESTS=Off.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138157/new/

https://reviews.llvm.org/D138157

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/CMakeLists.txt
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  llvm/docs/GwpAsan.rst

Index: llvm/docs/GwpAsan.rst
===
--- llvm/docs/GwpAsan.rst
+++ llvm/docs/GwpAsan.rst
@@ -143,9 +143,10 @@
   default visibility. This will override the compile time define;
 
 - Depending on allocator support (Scudo has support for this mechanism): Through
-  the environment variable ``GWP_ASAN_OPTIONS``, containing the options string
-  to be parsed. Options defined this way will override any definition made
-  through ``__gwp_asan_default_options``.
+  an environment variable, containing the options string to be parsed. In Scudo,
+  this is through `SCUDO_OPTIONS=GWP_ASAN_${OPTION_NAME}=${VALUE}` (e.g.
+  `SCUDO_OPTIONS=GWP_ASAN_SampleRate=100`). Options defined this way will
+  override any definition made through ``__gwp_asan_default_options``.
 
 The options string follows a syntax similar to ASan, where distinct options
 can be assigned in the same string, separated by colons.
@@ -216,9 +217,9 @@
 
 .. code:: console
 
-  $ clang++ -fsanitize=scudo -std=c++17 -g buggy_code.cpp
-  $ for i in `seq 1 200`; do
-  GWP_ASAN_OPTIONS="SampleRate=100" ./a.out > /dev/null;
+  $ clang++ -fsanitize=scudo -g buggy_code.cpp
+  $ for i in `seq 1 500`; do
+  SCUDO_OPTIONS="GWP_ASAN_SampleRate=100" ./a.out > /dev/null;
 done
   |
   | *** GWP-ASan detected a memory error ***
Index: compiler-rt/test/scudo/standalone/CMakeLists.txt
===
--- compiler-rt/test/scudo/standalone/CMakeLists.txt
+++ compiler-rt/test/scudo/standalone/CMakeLists.txt
@@ -10,12 +10,12 @@
   ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan/lit.site.cfg.py)
 list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan)
   endif()
-endif()
 
-add_lit_testsuite(check-scudo_standalone
-  "Running Scudo Standalone tests"
-  ${SCUDO_STANDALONE_TESTSUITES}
-  DEPENDS ${SCUDO_STANDALONE_TEST_DEPS})
+  add_lit_testsuite(check-scudo_standalone
+"Running Scudo Standalone tests"
+${SCUDO_STANDALONE_TESTSUITES}
+DEPENDS ${SCUDO_STANDALONE_TEST_DEPS})
 
-set_target_properties(check-scudo_standalone
-  PROPERTIES FOLDER "Compiler-RT Tests")
+  set_target_properties(check-scudo_standalone
+PROPERTIES FOLDER "Compiler-RT Tests")
+endif()
Index: compiler-rt/test/scudo/CMakeLists.txt
===
--- compiler-rt/test/scudo/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-set(SCUDO_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-set(SCUDO_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
-
-set(SCUDO_TESTSUITES)
-
-set(SCUDO_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(NOT COMPILER_RT_STANDALONE_BUILD)
-  list(APPEND SCUDO_TEST_DEPS scudo)
-endif()
-
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
-  )
-
-set(SCUDO_TEST_ARCH ${SCUDO_SUPPORTED_ARCH})
-foreach(arch ${SCUDO_TEST_ARCH})
-  set(SCUDO_TEST_TARGET_ARCH ${arch})
-  string(TOLOWER "-${arch}" SCUDO_TEST_CONFIG_SUFFIX)
-  get_test_cc_for_arch(${arch} SCUDO_TEST_TARGET_CC SCUDO_TEST_TARGET_CFLAGS)
-  string(TOUPPER ${arch} ARCH_UPPER_CASE)
-  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-
-  configure_lit_site_cfg(
-${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
-  list(APPEND SCUDO_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
-endforeach()
-
-add_subdirectory(standalone)
-
-add_lit_testsuite(check-scudo "Running the Scudo Hardened Allocator tests"
-  ${SCUDO_TESTSUITES}
-  DEPENDS ${SCUDO_TEST_DEPS})
-set_target_properties(check-scudo PROPERTIES FOLDER "Compiler-RT Misc")
Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/C

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-12-01 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: llvm/lib/CodeGen/GlobalMerge.cpp:657
+// Tagged global variables shouldn't be merged, as they are assigned unique
+// memory tags at runtime.
+if (GV.isTagged())

eugenis wrote:
> This comment is not convincing. The change description is right that some 
> globals can be merged, copy that here, or extend the comment a little to 
> explain why and under what assumptions.
Thanks, extended the comment.



Comment at: llvm/lib/MC/ELFObjectWriter.cpp:1344
+  // when relocating `end` symbols, and this can only be determined by the
+  // attributes of the symbol itself.
+  if (Sym->isMemtag())

eugenis wrote:
> Isn't a bigger reason that we need to know the address tag to put on the 
> pointer, and that requires a symbol, not a section reference?
removed this comment here, as this was moved into the parent patch 
https://reviews.llvm.org/D131863 and the comment was updated there. this 
comment references the old st_other-based implementation, whereas now it's 
needed for SHT_AARCH64_MEMTAG_GLOBALS_STATIC.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-12-01 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 479452.
hctim marked 2 inline comments as done.
hctim added a comment.

Rebase now that the parent is submitted, clean up an old comment. New commit 
message also incoming.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -66,6 +66,7 @@
 ; CHECK-NEXT:   Expand reduction intrinsics
 ; CHECK-NEXT:   Natural Loop Information
 ; CHECK-NEXT:   TLS Variable Hoist
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -26,6 +26,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   SME ABI Pass
 ; CHECK-NEXT:   Exception handling preparation
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -231,6 +231,7 @@
   initializeAArch64StackTaggingPass(*PR);
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -586,6 +587,7 @@
 
   TargetPassConfig::addIRPasses();
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -354,6 +354,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass()) {
   if (isWindowsArm64EC() && GV->getValueType()->isFunctionTy())
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,144 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+static bool shouldTagGlobal(GlobalVariable &G) {
+  if (!G.isT

[PATCH] D128958: Add assembler plumbing for sanitize_memtag

2022-12-01 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG850defb86164: Add assembler plumbing for sanitize_memtag 
(authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128958/new/

https://reviews.llvm.org/D128958

Files:
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag-stack_lto.c
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/MC/MCSymbolELF.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCMachOStreamer.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCSymbolELF.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
  llvm/test/MC/AArch64/global-tagging.ll

Index: llvm/test/MC/AArch64/global-tagging.ll
===
--- /dev/null
+++ llvm/test/MC/AArch64/global-tagging.ll
@@ -0,0 +1,46 @@
+;; Tagged symbols are only available on aarch64-linux-android.
+; RUN: not llc %s -mtriple=aarch64-linux-unknown
+; RUN: not llc %s -mtriple=x86_64-linux-unknown
+
+; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
+; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
+; RUN: llvm-mc -filetype=obj %t.S -triple=aarch64-linux-android31 -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; RUN: obj2yaml %t.o -o %t.yaml
+; RUN: FileCheck %s --input-file=%t.yaml --check-prefix=CHECK-YAML
+; RUN: yaml2obj %t.yaml -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; CHECK-RELOCS: Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} internal_four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} sixteen
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} huge
+; CHECK-RELOCS-NOT: specialcaselisted
+
+; CHECK-YAML:  Sections:
+; CHECK-YAML:  - Name: .rela.memtag.globals.static
+; CHECK-YAML-NOT:  - Name:
+; CHECK-YAML:  Relocations:
+; CHECK-YAML-NEXT: - Symbol: internal_four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: sixteen
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: huge
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: -
+
+; CHECK-ASM: .memtag internal_four
+; CHECK-ASM: .memtag four
+; CHECK-ASM: .memtag sixteen
+; CHECK-ASM: .memtag huge
+; CHECK-ASM-NOT: .memtag specialcaselisted
+
+@internal_four = internal global i32 1, sanitize_memtag
+@four = global i32 1, sanitize_memtag
+@sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
+@huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
+@specialcaselisted = global i16 2
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -34,6 +34,8 @@
 
   ~AArch64ELFObjectWriter() override = default;
 
+  MCSectionELF *getMemtagRelocsSection(MCContext &Ctx) const override;
+
 protected:
   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
 const MCFixup &Fixup, bool IsPCRel) const override;
@@ -453,6 +455,12 @@
   llvm_unreachable("Unimplemented fixup -> relocation");
 }
 
+MCSectionELF *
+AArch64ELFObjectWriter::getMemtagRelocsSection(MCContext &Ctx) const {
+  return Ctx.getELFSection(".memtag.globals.static",
+   ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0);
+}
+
 std::unique_ptr
 llvm::createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32) {
   return std::make_unique(OSABI, IsILP32);
Index: llvm/lib/MC/MCSymbolELF.cpp
===
--- llvm/lib/MC/MCSymbolELF.cpp
+++ llvm/lib/MC/MCSymbolELF.cpp
@@ -33,7 +33,10 @@
   ELF_WeakrefUsedInReloc_Shift = 11,
 
   // One bit.
-  ELF_BindingSet_Shift = 12
+  ELF_BindingSet_Shift = 12,
+
+  // One bit.
+  ELF_IsMemoryTagged_Shift = 13,
 };
 }
 
@@ -193,4 +196,16 @@
 bool MCSymbolELF::isBindingSet() const {
   return getFlags() & (0x1 << ELF_BindingSet_Shift);
 }
+
+bool MCSymbolELF::isMemtag() const {
+  return getFlags() & (0x1 << ELF_IsMemoryTagged_Shift);
+}
+
+void MCSymbolELF::setMemtag(bool Tagged) {
+  uint32_t OtherFlags = getFlags() & ~(1 << ELF_IsMemoryTagged_Shift);
+  if (Tagged)
+setFlags(OtherFlags | (1 << ELF_IsMemoryTagged_Shift));
+  else
+setFlags(OtherFlags);
+}
 }
Index: llvm/lib/MC/MCParser/AsmParser.cpp

[PATCH] D128958: Add assembler plumbing for sanitize_memtag

2022-11-28 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: llvm/lib/MC/ELFObjectWriter.cpp:622
+  assert(MemtagRelocs != nullptr &&
+ "Tagged globals are only supported on AArch64");
+  Asm.registerSection(*MemtagRelocs);

fmayer wrote:
> Is the story here that on non-AArch64, this function gets run, but there will 
> be no SymE.isMemtag()?
Correct, and getMemtagRelocsSection() returns nullptr on every arch except 
aarch64.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128958/new/

https://reviews.llvm.org/D128958

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128958: Add assembler plumbing for sanitize_memtag

2022-11-28 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 478367.
hctim marked an inline comment as done.
hctim added a comment.

Update comment for .memtag globals when generating object files on 
non-MTE-globals supported architectures, and move said comment from an assert 
to a fatal error.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128958/new/

https://reviews.llvm.org/D128958

Files:
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag-stack_lto.c
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/MC/MCSymbolELF.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCMachOStreamer.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCSymbolELF.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
  llvm/test/MC/AArch64/global-tagging.ll

Index: llvm/test/MC/AArch64/global-tagging.ll
===
--- /dev/null
+++ llvm/test/MC/AArch64/global-tagging.ll
@@ -0,0 +1,46 @@
+;; Tagged symbols are only available on aarch64-linux-android.
+; RUN: not llc %s -mtriple=aarch64-linux-unknown
+; RUN: not llc %s -mtriple=x86_64-linux-unknown
+
+; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
+; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
+; RUN: llvm-mc -filetype=obj %t.S -triple=aarch64-linux-android31 -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; RUN: obj2yaml %t.o -o %t.yaml
+; RUN: FileCheck %s --input-file=%t.yaml --check-prefix=CHECK-YAML
+; RUN: yaml2obj %t.yaml -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; CHECK-RELOCS: Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} internal_four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} sixteen
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} huge
+; CHECK-RELOCS-NOT: specialcaselisted
+
+; CHECK-YAML:  Sections:
+; CHECK-YAML:  - Name: .rela.memtag.globals.static
+; CHECK-YAML-NOT:  - Name:
+; CHECK-YAML:  Relocations:
+; CHECK-YAML-NEXT: - Symbol: internal_four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: sixteen
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: huge
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: -
+
+; CHECK-ASM: .memtag internal_four
+; CHECK-ASM: .memtag four
+; CHECK-ASM: .memtag sixteen
+; CHECK-ASM: .memtag huge
+; CHECK-ASM-NOT: .memtag specialcaselisted
+
+@internal_four = internal global i32 1, sanitize_memtag
+@four = global i32 1, sanitize_memtag
+@sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
+@huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
+@specialcaselisted = global i16 2
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -34,6 +34,8 @@
 
   ~AArch64ELFObjectWriter() override = default;
 
+  MCSectionELF *getMemtagRelocsSection(MCContext &Ctx) const override;
+
 protected:
   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
 const MCFixup &Fixup, bool IsPCRel) const override;
@@ -453,6 +455,12 @@
   llvm_unreachable("Unimplemented fixup -> relocation");
 }
 
+MCSectionELF *
+AArch64ELFObjectWriter::getMemtagRelocsSection(MCContext &Ctx) const {
+  return Ctx.getELFSection(".memtag.globals.static",
+   ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0);
+}
+
 std::unique_ptr
 llvm::createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32) {
   return std::make_unique(OSABI, IsILP32);
Index: llvm/lib/MC/MCSymbolELF.cpp
===
--- llvm/lib/MC/MCSymbolELF.cpp
+++ llvm/lib/MC/MCSymbolELF.cpp
@@ -33,7 +33,10 @@
   ELF_WeakrefUsedInReloc_Shift = 11,
 
   // One bit.
-  ELF_BindingSet_Shift = 12
+  ELF_BindingSet_Shift = 12,
+
+  // One bit.
+  ELF_IsMemoryTagged_Shift = 13,
 };
 }
 
@@ -193,4 +196,16 @@
 bool MCSymbolELF::isBindingSet() const {
   return getFlags() & (0x1 << ELF_BindingSet_Shift);
 }
+
+bool MCSymbolELF::isMemtag() const {
+  return getFlags() & (0x1 << ELF_IsMemoryTagged_Shift);
+}
+
+void MCSymbolELF::setMemtag(bool Tagged) {
+  uint32_t OtherFlags = getFlags() & ~(1 << ELF_IsMemoryTagged_Shift);
+  if (Tagged)
+setFlags(OtherFlags | (1 << ELF_IsMemoryTagged_Shift));
+  else
+setFlags(OtherFlags);
+}
 }
Index: llvm/lib/MC/MCPar

[PATCH] D128958: Add assembler plumbing for sanitize_memtag

2022-11-23 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 477620.
hctim marked 2 inline comments as done.
hctim added a comment.

Move isMemtag below assert(Sym)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128958/new/

https://reviews.llvm.org/D128958

Files:
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag-stack_lto.c
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/MC/MCSymbolELF.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCMachOStreamer.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCSymbolELF.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
  llvm/test/MC/AArch64/global-tagging.ll

Index: llvm/test/MC/AArch64/global-tagging.ll
===
--- /dev/null
+++ llvm/test/MC/AArch64/global-tagging.ll
@@ -0,0 +1,46 @@
+;; Tagged symbols are only available on aarch64-linux-android.
+; RUN: not llc %s -mtriple=aarch64-linux-unknown
+; RUN: not llc %s -mtriple=x86_64-linux-unknown
+
+; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
+; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
+; RUN: llvm-mc -filetype=obj %t.S -triple=aarch64-linux-android31 -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; RUN: obj2yaml %t.o -o %t.yaml
+; RUN: FileCheck %s --input-file=%t.yaml --check-prefix=CHECK-YAML
+; RUN: yaml2obj %t.yaml -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; CHECK-RELOCS: Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} internal_four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} sixteen
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} huge
+; CHECK-RELOCS-NOT: specialcaselisted
+
+; CHECK-YAML:  Sections:
+; CHECK-YAML:  - Name: .rela.memtag.globals.static
+; CHECK-YAML-NOT:  - Name:
+; CHECK-YAML:  Relocations:
+; CHECK-YAML-NEXT: - Symbol: internal_four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: sixteen
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: huge
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: -
+
+; CHECK-ASM: .memtag internal_four
+; CHECK-ASM: .memtag four
+; CHECK-ASM: .memtag sixteen
+; CHECK-ASM: .memtag huge
+; CHECK-ASM-NOT: .memtag specialcaselisted
+
+@internal_four = internal global i32 1, sanitize_memtag
+@four = global i32 1, sanitize_memtag
+@sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
+@huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
+@specialcaselisted = global i16 2
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -34,6 +34,8 @@
 
   ~AArch64ELFObjectWriter() override = default;
 
+  MCSectionELF *getMemtagRelocsSection(MCContext &Ctx) const override;
+
 protected:
   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
 const MCFixup &Fixup, bool IsPCRel) const override;
@@ -453,6 +455,12 @@
   llvm_unreachable("Unimplemented fixup -> relocation");
 }
 
+MCSectionELF *
+AArch64ELFObjectWriter::getMemtagRelocsSection(MCContext &Ctx) const {
+  return Ctx.getELFSection(".memtag.globals.static",
+   ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0);
+}
+
 std::unique_ptr
 llvm::createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32) {
   return std::make_unique(OSABI, IsILP32);
Index: llvm/lib/MC/MCSymbolELF.cpp
===
--- llvm/lib/MC/MCSymbolELF.cpp
+++ llvm/lib/MC/MCSymbolELF.cpp
@@ -33,7 +33,10 @@
   ELF_WeakrefUsedInReloc_Shift = 11,
 
   // One bit.
-  ELF_BindingSet_Shift = 12
+  ELF_BindingSet_Shift = 12,
+
+  // One bit.
+  ELF_IsMemoryTagged_Shift = 13,
 };
 }
 
@@ -193,4 +196,16 @@
 bool MCSymbolELF::isBindingSet() const {
   return getFlags() & (0x1 << ELF_BindingSet_Shift);
 }
+
+bool MCSymbolELF::isMemtag() const {
+  return getFlags() & (0x1 << ELF_IsMemoryTagged_Shift);
+}
+
+void MCSymbolELF::setMemtag(bool Tagged) {
+  uint32_t OtherFlags = getFlags() & ~(1 << ELF_IsMemoryTagged_Shift);
+  if (Tagged)
+setFlags(OtherFlags | (1 << ELF_IsMemoryTagged_Shift));
+  else
+setFlags(OtherFlags);
+}
 }
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm

[PATCH] D128958: Add assembler plumbing for sanitize_memtag

2022-11-23 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 477600.
hctim added a comment.

Use new MemtagABI section types, now that it's merged upstream: 
https://github.com/ARM-software/abi-aa/blob/main/memtagabielf64/memtagabielf64.rst


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128958/new/

https://reviews.llvm.org/D128958

Files:
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag-stack_lto.c
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/MC/MCSymbolELF.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCMachOStreamer.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCSymbolELF.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
  llvm/test/MC/AArch64/global-tagging.ll

Index: llvm/test/MC/AArch64/global-tagging.ll
===
--- /dev/null
+++ llvm/test/MC/AArch64/global-tagging.ll
@@ -0,0 +1,46 @@
+;; Tagged symbols are only available on aarch64-linux-android.
+; RUN: not llc %s -mtriple=aarch64-linux-unknown
+; RUN: not llc %s -mtriple=x86_64-linux-unknown
+
+; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
+; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
+; RUN: llvm-mc -filetype=obj %t.S -triple=aarch64-linux-android31 -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; RUN: obj2yaml %t.o -o %t.yaml
+; RUN: FileCheck %s --input-file=%t.yaml --check-prefix=CHECK-YAML
+; RUN: yaml2obj %t.yaml -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; CHECK-RELOCS: Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} internal_four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} sixteen
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} huge
+; CHECK-RELOCS-NOT: specialcaselisted
+
+; CHECK-YAML:  Sections:
+; CHECK-YAML:  - Name: .rela.memtag.globals.static
+; CHECK-YAML-NOT:  - Name:
+; CHECK-YAML:  Relocations:
+; CHECK-YAML-NEXT: - Symbol: internal_four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: sixteen
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: huge
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: -
+
+; CHECK-ASM: .memtag internal_four
+; CHECK-ASM: .memtag four
+; CHECK-ASM: .memtag sixteen
+; CHECK-ASM: .memtag huge
+; CHECK-ASM-NOT: .memtag specialcaselisted
+
+@internal_four = internal global i32 1, sanitize_memtag
+@four = global i32 1, sanitize_memtag
+@sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
+@huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
+@specialcaselisted = global i16 2
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -34,6 +34,8 @@
 
   ~AArch64ELFObjectWriter() override = default;
 
+  MCSectionELF *getMemtagRelocsSection(MCContext &Ctx) const override;
+
 protected:
   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
 const MCFixup &Fixup, bool IsPCRel) const override;
@@ -453,6 +455,12 @@
   llvm_unreachable("Unimplemented fixup -> relocation");
 }
 
+MCSectionELF *
+AArch64ELFObjectWriter::getMemtagRelocsSection(MCContext &Ctx) const {
+  return Ctx.getELFSection(".memtag.globals.static",
+   ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0);
+}
+
 std::unique_ptr
 llvm::createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32) {
   return std::make_unique(OSABI, IsILP32);
Index: llvm/lib/MC/MCSymbolELF.cpp
===
--- llvm/lib/MC/MCSymbolELF.cpp
+++ llvm/lib/MC/MCSymbolELF.cpp
@@ -33,7 +33,10 @@
   ELF_WeakrefUsedInReloc_Shift = 11,
 
   // One bit.
-  ELF_BindingSet_Shift = 12
+  ELF_BindingSet_Shift = 12,
+
+  // One bit.
+  ELF_IsMemoryTagged_Shift = 13,
 };
 }
 
@@ -193,4 +196,16 @@
 bool MCSymbolELF::isBindingSet() const {
   return getFlags() & (0x1 << ELF_BindingSet_Shift);
 }
+
+bool MCSymbolELF::isMemtag() const {
+  return getFlags() & (0x1 << ELF_IsMemoryTagged_Shift);
+}
+
+void MCSymbolELF::setMemtag(bool Tagged) {
+  uint32_t OtherFlags = getFlags() & ~(1 << ELF_IsMemoryTagged_Shift);
+  if (Tagged)
+setFlags(OtherFlags | (1 << ELF_IsMemoryTagged_Shift));
+  else
+setFlags(OtherFlags);
+}
 }
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===

[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-11-23 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Thanks for the detailed information folks. I'll probably fix it up and 
re-submit next week (after the US holidays) given that the blast radius seems 
to be bigger than I expected.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138157/new/

https://reviews.llvm.org/D138157

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-11-22 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGab1a5991fe76: Make -fsanitize=scudo use scudo_standalone. 
Delete check-scudo. (authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138157/new/

https://reviews.llvm.org/D138157

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/CMakeLists.txt
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/scudo/CMakeLists.txt
  llvm/docs/GwpAsan.rst

Index: llvm/docs/GwpAsan.rst
===
--- llvm/docs/GwpAsan.rst
+++ llvm/docs/GwpAsan.rst
@@ -143,9 +143,10 @@
   default visibility. This will override the compile time define;
 
 - Depending on allocator support (Scudo has support for this mechanism): Through
-  the environment variable ``GWP_ASAN_OPTIONS``, containing the options string
-  to be parsed. Options defined this way will override any definition made
-  through ``__gwp_asan_default_options``.
+  an environment variable, containing the options string to be parsed. In Scudo,
+  this is through `SCUDO_OPTIONS=GWP_ASAN_${OPTION_NAME}=${VALUE}` (e.g.
+  `SCUDO_OPTIONS=GWP_ASAN_SampleRate=100`). Options defined this way will
+  override any definition made through ``__gwp_asan_default_options``.
 
 The options string follows a syntax similar to ASan, where distinct options
 can be assigned in the same string, separated by colons.
@@ -216,9 +217,9 @@
 
 .. code:: console
 
-  $ clang++ -fsanitize=scudo -std=c++17 -g buggy_code.cpp
-  $ for i in `seq 1 200`; do
-  GWP_ASAN_OPTIONS="SampleRate=100" ./a.out > /dev/null;
+  $ clang++ -fsanitize=scudo -g buggy_code.cpp
+  $ for i in `seq 1 500`; do
+  SCUDO_OPTIONS="GWP_ASAN_SampleRate=100" ./a.out > /dev/null;
 done
   |
   | *** GWP-ASan detected a memory error ***
Index: compiler-rt/test/scudo/CMakeLists.txt
===
--- compiler-rt/test/scudo/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-set(SCUDO_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-set(SCUDO_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
-
-set(SCUDO_TESTSUITES)
-
-set(SCUDO_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(NOT COMPILER_RT_STANDALONE_BUILD)
-  list(APPEND SCUDO_TEST_DEPS scudo)
-endif()
-
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
-  )
-
-set(SCUDO_TEST_ARCH ${SCUDO_SUPPORTED_ARCH})
-foreach(arch ${SCUDO_TEST_ARCH})
-  set(SCUDO_TEST_TARGET_ARCH ${arch})
-  string(TOLOWER "-${arch}" SCUDO_TEST_CONFIG_SUFFIX)
-  get_test_cc_for_arch(${arch} SCUDO_TEST_TARGET_CC SCUDO_TEST_TARGET_CFLAGS)
-  string(TOUPPER ${arch} ARCH_UPPER_CASE)
-  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-
-  configure_lit_site_cfg(
-${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
-  list(APPEND SCUDO_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
-endforeach()
-
-add_subdirectory(standalone)
-
-add_lit_testsuite(check-scudo "Running the Scudo Hardened Allocator tests"
-  ${SCUDO_TESTSUITES}
-  DEPENDS ${SCUDO_TEST_DEPS})
-set_target_properties(check-scudo PROPERTIES FOLDER "Compiler-RT Misc")
Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/CMakeLists.txt
+++ compiler-rt/test/CMakeLists.txt
@@ -19,6 +19,8 @@
 # BlocksRuntime (and most of builtins) testsuites are not yet ported to lit.
 # add_subdirectory(BlocksRuntime)
 
+add_subdirectory(scudo/standalone)
+
 set(SANITIZER_COMMON_LIT_TEST_DEPS)
 
 if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE)
Index: compiler-rt/lib/CMakeLists.txt
===
--- compiler-rt/lib/CMakeLists.txt
+++ compiler-rt/lib/CMakeLists.txt
@@ -24,12 +24,13 @@
 function(compiler_rt_build_runtime runtime)
   string(TOUPPER ${runtime} runtime_uppercase)
   if(COMPILER_RT_HAS_${runtime_uppercase})
-add_subdirectory(${runtime})
 if(${runtime} STREQUAL tsan)
   add_subdirectory(tsan/dd)
 endif()
-if(${runtime} STREQUAL scudo)
+if(${runtime} STREQUAL scudo_standalone)
   add_subdirectory(scudo/standalone)
+else()
+  add_subdirectory(${runtime})
 endif()
   endif()
 endfunction()
@@ -48,6 +49,8 @@
   foreach(sanitizer ${COMPILER_RT_SANITIZERS_TO_BUILD})
 compiler_rt_build_runtime(${sanitizer})
   endforeach()
+
+  compiler_rt_build_runtime(scudo_standalone)
 endif()
 
 if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE)
Index: compiler-rt/cmake/config-ix.cmake
===
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake

[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-11-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D138157#3935173 , @phosek wrote:

> Is the plan to eventually rename `scudo_standalone` to `scudo` once the 
> santiizer-based Scudo implementation is deleted?

Ideally, yes (as well as make scudo_standalone not be in a subfolder). 
Practically, no, because of all the folks that depend on it (you@fuchsia, 
android, llvm-libc).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138157/new/

https://reviews.llvm.org/D138157

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-11-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: llvm/docs/GwpAsan.rst:174
 
++-++
-| PerfectlyRightAlign| false   | When allocations are right-aligned, 
should we perfectly align them up to the   |
-|| | page boundary? By default (false), we 
round up allocation size to the nearest  |

vitalybuka wrote:
> how this related to the patch?
unrelated, was a drive-by cleanup. i'll remove it from the diff.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138157/new/

https://reviews.llvm.org/D138157

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-11-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 476241.
hctim marked 2 inline comments as done.
hctim added a comment.

Remove unrelated diff from doc.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138157/new/

https://reviews.llvm.org/D138157

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/CMakeLists.txt
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/scudo/CMakeLists.txt
  llvm/docs/GwpAsan.rst

Index: llvm/docs/GwpAsan.rst
===
--- llvm/docs/GwpAsan.rst
+++ llvm/docs/GwpAsan.rst
@@ -143,9 +143,10 @@
   default visibility. This will override the compile time define;
 
 - Depending on allocator support (Scudo has support for this mechanism): Through
-  the environment variable ``GWP_ASAN_OPTIONS``, containing the options string
-  to be parsed. Options defined this way will override any definition made
-  through ``__gwp_asan_default_options``.
+  an environment variable, containing the options string to be parsed. In Scudo,
+  this is through `SCUDO_OPTIONS=GWP_ASAN_${OPTION_NAME}=${VALUE}` (e.g.
+  `SCUDO_OPTIONS=GWP_ASAN_SampleRate=100`). Options defined this way will
+  override any definition made through ``__gwp_asan_default_options``.
 
 The options string follows a syntax similar to ASan, where distinct options
 can be assigned in the same string, separated by colons.
@@ -216,9 +217,9 @@
 
 .. code:: console
 
-  $ clang++ -fsanitize=scudo -std=c++17 -g buggy_code.cpp
-  $ for i in `seq 1 200`; do
-  GWP_ASAN_OPTIONS="SampleRate=100" ./a.out > /dev/null;
+  $ clang++ -fsanitize=scudo -g buggy_code.cpp
+  $ for i in `seq 1 500`; do
+  SCUDO_OPTIONS="GWP_ASAN_SampleRate=100" ./a.out > /dev/null;
 done
   |
   | *** GWP-ASan detected a memory error ***
Index: compiler-rt/test/scudo/CMakeLists.txt
===
--- compiler-rt/test/scudo/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-set(SCUDO_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-set(SCUDO_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
-
-set(SCUDO_TESTSUITES)
-
-set(SCUDO_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(NOT COMPILER_RT_STANDALONE_BUILD)
-  list(APPEND SCUDO_TEST_DEPS scudo)
-endif()
-
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
-  )
-
-set(SCUDO_TEST_ARCH ${SCUDO_SUPPORTED_ARCH})
-foreach(arch ${SCUDO_TEST_ARCH})
-  set(SCUDO_TEST_TARGET_ARCH ${arch})
-  string(TOLOWER "-${arch}" SCUDO_TEST_CONFIG_SUFFIX)
-  get_test_cc_for_arch(${arch} SCUDO_TEST_TARGET_CC SCUDO_TEST_TARGET_CFLAGS)
-  string(TOUPPER ${arch} ARCH_UPPER_CASE)
-  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-
-  configure_lit_site_cfg(
-${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
-  list(APPEND SCUDO_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
-endforeach()
-
-add_subdirectory(standalone)
-
-add_lit_testsuite(check-scudo "Running the Scudo Hardened Allocator tests"
-  ${SCUDO_TESTSUITES}
-  DEPENDS ${SCUDO_TEST_DEPS})
-set_target_properties(check-scudo PROPERTIES FOLDER "Compiler-RT Misc")
Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/CMakeLists.txt
+++ compiler-rt/test/CMakeLists.txt
@@ -19,6 +19,8 @@
 # BlocksRuntime (and most of builtins) testsuites are not yet ported to lit.
 # add_subdirectory(BlocksRuntime)
 
+add_subdirectory(scudo/standalone)
+
 set(SANITIZER_COMMON_LIT_TEST_DEPS)
 
 if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE)
Index: compiler-rt/lib/CMakeLists.txt
===
--- compiler-rt/lib/CMakeLists.txt
+++ compiler-rt/lib/CMakeLists.txt
@@ -24,12 +24,13 @@
 function(compiler_rt_build_runtime runtime)
   string(TOUPPER ${runtime} runtime_uppercase)
   if(COMPILER_RT_HAS_${runtime_uppercase})
-add_subdirectory(${runtime})
 if(${runtime} STREQUAL tsan)
   add_subdirectory(tsan/dd)
 endif()
-if(${runtime} STREQUAL scudo)
+if(${runtime} STREQUAL scudo_standalone)
   add_subdirectory(scudo/standalone)
+else()
+  add_subdirectory(${runtime})
 endif()
   endif()
 endfunction()
@@ -48,6 +49,8 @@
   foreach(sanitizer ${COMPILER_RT_SANITIZERS_TO_BUILD})
 compiler_rt_build_runtime(${sanitizer})
   endforeach()
+
+  compiler_rt_build_runtime(scudo_standalone)
 endif()
 
 if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE)
Index: compiler-rt/cmake/config-ix.cmake
===
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -619,9 +619,6 @@
   list_intersect(CFI_SUPPORTED_ARCH
 ALL_CFI_SUPPORTED_ARCH
 SANITIZER_COMMON_

[PATCH] D138157: Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.

2022-11-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: vitalybuka.
Herald added subscribers: Enna1, abrachet, phosek, cryptoad.
Herald added a project: All.
hctim requested review of this revision.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits, MaskRay.
Herald added projects: clang, Sanitizers, LLVM.

Leaves the implementation and tests files in-place for right now, but
deletes the ability to build the old sanitizer-common based scudo. This
has been on life-support for a long time, and the newer scudo_standalone
is much better supported and maintained.

Also patches up some GWP-ASan wording, primarily related to the fact
that -fsanitize=scudo now is scudo_standalone, and therefore the way to
reference the GWP-ASan options through the environment variable has
changed.

Future follow-up patches will delete the original scudo, and migrate all
its tests over to be part of the scudo_standalone test suite.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138157

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/CMakeLists.txt
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/scudo/CMakeLists.txt
  llvm/docs/GwpAsan.rst

Index: llvm/docs/GwpAsan.rst
===
--- llvm/docs/GwpAsan.rst
+++ llvm/docs/GwpAsan.rst
@@ -143,9 +143,10 @@
   default visibility. This will override the compile time define;
 
 - Depending on allocator support (Scudo has support for this mechanism): Through
-  the environment variable ``GWP_ASAN_OPTIONS``, containing the options string
-  to be parsed. Options defined this way will override any definition made
-  through ``__gwp_asan_default_options``.
+  an environment variable, containing the options string to be parsed. In Scudo,
+  this is through `SCUDO_OPTIONS=GWP_ASAN_${OPTION_NAME}=${VALUE}` (e.g.
+  `SCUDO_OPTIONS=GWP_ASAN_SampleRate=100`). Options defined this way will
+  override any definition made through ``__gwp_asan_default_options``.
 
 The options string follows a syntax similar to ASan, where distinct options
 can be assigned in the same string, separated by colons.
@@ -171,17 +172,12 @@
 ++-++
 | Enabled| true| Is GWP-ASan enabled?   |
 ++-++
-| PerfectlyRightAlign| false   | When allocations are right-aligned, should we perfectly align them up to the   |
-|| | page boundary? By default (false), we round up allocation size to the nearest  |
-|| | power of two (2, 4, 8, 16) up to a maximum of 16-byte alignment for|
-|| | performance reasons. Setting this to true can find single byte |
-|| | buffer-overflows at the cost of performance, and may be incompatible with  |
-|| | some architectures.|
+| help   | false   | Print a summart of the available options.  |
 ++-++
 | MaxSimultaneousAllocations | 16  | Number of simultaneously-guarded allocations available in the pool.|
 ++-++
 | SampleRate | 5000| The probability (1 / SampleRate) that a page is selected for GWP-ASan  |
-|| | sampling. Sample rates up to (2^31 - 1) are supported. |
+|| | sampling. Sample rates up to (2^30 - 1) are supported. |
 ++-++
 | InstallSignalHandlers  | true| Install GWP-ASan signal handlers for SIGSEGV during dynamic loading. This  |
 || | allows better error reports by providing stack traces for allocation and   |
@@ -216,9 +212,9 @@
 
 .. code:: console
 
-  $ clang++ -fsanitize=scudo -std=c++17 -g buggy_code.cpp
-  $ for i in `seq 1 200`; do
-  GWP_ASAN_OPTIONS="SampleRate=100" ./a.out > /dev/null;
+  $ clang++ -fsanitize=scudo -g buggy_code.cpp
+  $ for i in `seq 1 500`; do
+  SCUDO_OPTIONS="GWP_ASAN_SampleRate=100" ./a.out > /dev/null;
 done
   |
   | *** GWP-ASan detected a memory

[PATCH] D128958: Add assembler plumbing for sanitize_memtag

2022-09-12 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 459534.
hctim added a comment.

Remove unnecessary hasSanitizerMetadata()


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128958/new/

https://reviews.llvm.org/D128958

Files:
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag-stack_lto.c
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/MC/MCSymbolELF.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCMachOStreamer.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCSymbolELF.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
  llvm/test/MC/AArch64/global-tagging.ll

Index: llvm/test/MC/AArch64/global-tagging.ll
===
--- /dev/null
+++ llvm/test/MC/AArch64/global-tagging.ll
@@ -0,0 +1,46 @@
+;; Tagged symbols are only available on aarch64-linux-android.
+; RUN: not llc %s -mtriple=aarch64-linux-unknown
+; RUN: not llc %s -mtriple=x86_64-linux-unknown
+
+; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
+; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
+; RUN: llvm-mc -filetype=obj %t.S -triple=aarch64-linux-android31 -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; RUN: obj2yaml %t.o -o %t.yaml
+; RUN: FileCheck %s --input-file=%t.yaml --check-prefix=CHECK-YAML
+; RUN: yaml2obj %t.yaml -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; CHECK-RELOCS: Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} internal_four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} sixteen
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} huge
+; CHECK-RELOCS-NOT: specialcaselisted
+
+; CHECK-YAML:  Sections:
+; CHECK-YAML:  - Name: .rela.memtag.globals.static
+; CHECK-YAML-NOT:  - Name:
+; CHECK-YAML:  Relocations:
+; CHECK-YAML-NEXT: - Symbol: internal_four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: sixteen
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: huge
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: -
+
+; CHECK-ASM: .memtag internal_four
+; CHECK-ASM: .memtag four
+; CHECK-ASM: .memtag sixteen
+; CHECK-ASM: .memtag huge
+; CHECK-ASM-NOT: .memtag specialcaselisted
+
+@internal_four = internal global i32 1, sanitize_memtag
+@four = global i32 1, sanitize_memtag
+@sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
+@huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
+@specialcaselisted = global i16 2
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -34,6 +34,8 @@
 
   ~AArch64ELFObjectWriter() override = default;
 
+  MCSectionELF *getMemtagRelocsSection(MCContext &Ctx) const override;
+
 protected:
   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
 const MCFixup &Fixup, bool IsPCRel) const override;
@@ -453,6 +455,12 @@
   llvm_unreachable("Unimplemented fixup -> relocation");
 }
 
+MCSectionELF *
+AArch64ELFObjectWriter::getMemtagRelocsSection(MCContext &Ctx) const {
+  return Ctx.getELFSection(".memtag.globals.static",
+   ELF::SHT_ANDROID_MEMTAG_GLOBALS_STATIC, 0);
+}
+
 std::unique_ptr
 llvm::createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32) {
   return std::make_unique(OSABI, IsILP32);
Index: llvm/lib/MC/MCSymbolELF.cpp
===
--- llvm/lib/MC/MCSymbolELF.cpp
+++ llvm/lib/MC/MCSymbolELF.cpp
@@ -33,7 +33,10 @@
   ELF_WeakrefUsedInReloc_Shift = 11,
 
   // One bit.
-  ELF_BindingSet_Shift = 12
+  ELF_BindingSet_Shift = 12,
+
+  // One bit.
+  ELF_IsMemoryTagged_Shift = 13,
 };
 }
 
@@ -193,4 +196,16 @@
 bool MCSymbolELF::isBindingSet() const {
   return getFlags() & (0x1 << ELF_BindingSet_Shift);
 }
+
+bool MCSymbolELF::isMemtag() const {
+  return getFlags() & (0x1 << ELF_IsMemoryTagged_Shift);
+}
+
+void MCSymbolELF::setMemtag(bool Tagged) {
+  uint32_t OtherFlags = getFlags() & ~(1 << ELF_IsMemoryTagged_Shift);
+  if (Tagged)
+setFlags(OtherFlags | (1 << ELF_IsMemoryTagged_Shift));
+  else
+setFlags(OtherFlags);
+}
 }
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:25
+
+using namespace llvm;
+

fmayer wrote:
> why don't we put this into the llvm namespace rather than using?
common for code in this folder, `INITIALIZE_PASS_BEGIN` (below) errors out not 
being in the `llvm` namespace, but also warns about redundantly using `llvm::` 
in the macro expansion if you explicitly use the namespace...



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:29
+
+namespace {
+

tschuett wrote:
> I believe you are going too far with the anonymous namespace. There is no 
> need for static functions in anonymous namespaces.
> 
> https://llvm.org/docs/CodingStandards.html#anonymous-namespaces
moved everything but the class out of the namespace



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:93
+
+  uint64_t NewSize = alignTo(SizeInBytes, 16);
+  if (SizeInBytes != NewSize) {

tschuett wrote:
> If the `16` is the size of the granule, then it deserves to be named 
> constant. 
thanks, done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 458536.
hctim marked 2 inline comments as done.
hctim added a comment.

Some namespace moving and shaking.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -74,6 +74,7 @@
 ; CHECK-NEXT:   Expand reduction intrinsics
 ; CHECK-NEXT:   Natural Loop Information
 ; CHECK-NEXT:   TLS Variable Hoist
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -24,6 +24,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   Exception handling preparation
 ; CHECK-NEXT:   Safe Stack instrumentation pass
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -230,6 +230,7 @@
   initializeAArch64StackTaggingPass(*PR);
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -579,6 +580,7 @@
 
   TargetPassConfig::addIRPasses();
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -319,6 +319,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass())
   return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,144 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+static bool shouldTagGlobal(GlobalVariable &G) {
+  if (!G.isTagged())
+return fals

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 458487.
hctim marked an inline comment as done.
hctim added a comment.

Update inlined constants to use named constant.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -74,6 +74,7 @@
 ; CHECK-NEXT:   Expand reduction intrinsics
 ; CHECK-NEXT:   Natural Loop Information
 ; CHECK-NEXT:   TLS Variable Hoist
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -24,6 +24,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   Exception handling preparation
 ; CHECK-NEXT:   Safe Stack instrumentation pass
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -230,6 +230,7 @@
   initializeAArch64StackTaggingPass(*PR);
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -579,6 +580,7 @@
 
   TargetPassConfig::addIRPasses();
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -319,6 +319,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass())
   return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,146 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+namespace {
+
+class AArch64GlobalsTagging : public ModulePass {
+public:

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:60
+  // gadgets.
+  if (G.getName().startswith("llvm.") || G.isThreadLocal() || G.isConstant()) {
+Meta.Memtag = false;

fmayer wrote:
> not necessarily in this CL: do we want some attribute to turn off 
> instrumentation?
memtag sanitization is not-implicit (i.e. it's opt-in rather than opt-out): 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/GlobalValue.h#L327,
 so a turn-off attribute should be unnecessary



Comment at: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp:108
+
+Value *Indices2[2];
+IRBuilder<> IRB(M.getContext());

fmayer wrote:
> what does this do?
dead code, thanks, removed


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-07 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 458472.
hctim marked 3 inline comments as done.
hctim added a comment.

Update from Florian's comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133392/new/

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -74,6 +74,7 @@
 ; CHECK-NEXT:   Expand reduction intrinsics
 ; CHECK-NEXT:   Natural Loop Information
 ; CHECK-NEXT:   TLS Variable Hoist
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -24,6 +24,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   Exception handling preparation
 ; CHECK-NEXT:   Safe Stack instrumentation pass
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -230,6 +230,7 @@
   initializeAArch64StackTaggingPass(*PR);
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -579,6 +580,7 @@
 
   TargetPassConfig::addIRPasses();
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -319,6 +319,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass())
   return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
Index: llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
===
--- /dev/null
+++ llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -0,0 +1,146 @@
+//===- AArch64GlobalsTagging.cpp - Global tagging in IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//===--===//
+
+#include "AArch64.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+static const Align kTagGranuleSize = Align(16);
+
+namespace {
+
+class AArch64GlobalsTagging : public ModulePass {
+public:
+  static char I

[PATCH] D133392: [MTE] Add AArch64GlobalsTagging Pass

2022-09-06 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added reviewers: fmayer, eugenis.
Herald added subscribers: hiraditya, kristof.beyls, mgorny.
Herald added a project: All.
hctim requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Adds the IR pass to tag global variables. You can see the official ABI
proposal at https://github.com/ARM-software/abi-aa/pull/166.

This pass very simply goes over the taggable global variables, re-sizes
and re-aligns them so that they're matched up to the tag granule size
(16 bytes), and marks them as tagged. This allows the backend to create
relocations and put them into a special section.

Global merge must be suppressed for tagged globals, as each global
variable must have a unique tag. This can possibly be relaxed in future;
globals that are identical in size, alignment, and content can
possibly be merged. The major problem comes from tail- or head-merging.

In addition, make sure that tagged globals in object files have
referenced symtab entries for relocations. This is necessary for the
linker to know where a tag should come from, as there's some special
dynamic relocation logic that applies
(https://github.com/ARM-software/abi-aa/blob/64458f8608b69536880501caced7c95a10a49d24/memtagabielf64/memtagabielf64.rst#extended-semantics-of-r-aarch64-relative)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133392

Files:
  clang/test/CodeGen/memtag-globals-asm.cpp
  llvm/lib/CodeGen/GlobalMerge.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll

Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -74,6 +74,7 @@
 ; CHECK-NEXT:   Expand reduction intrinsics
 ; CHECK-NEXT:   Natural Loop Information
 ; CHECK-NEXT:   TLS Variable Hoist
+; CHECK-NEXT: AArch64 Globals Tagging
 ; CHECK-NEXT: Stack Safety Analysis
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Dominator Tree Construction
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -24,6 +24,8 @@
 ; CHECK-NEXT:   Expand vector predication intrinsics
 ; CHECK-NEXT:   Scalarize Masked Memory Intrinsics
 ; CHECK-NEXT:   Expand reduction intrinsics
+; CHECK-NEXT: AArch64 Globals Tagging
+; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   Exception handling preparation
 ; CHECK-NEXT:   Safe Stack instrumentation pass
Index: llvm/lib/Target/AArch64/CMakeLists.txt
===
--- llvm/lib/Target/AArch64/CMakeLists.txt
+++ llvm/lib/Target/AArch64/CMakeLists.txt
@@ -56,6 +56,7 @@
   AArch64FastISel.cpp
   AArch64A53Fix835769.cpp
   AArch64FrameLowering.cpp
+  AArch64GlobalsTagging.cpp
   AArch64CompressJumpTables.cpp
   AArch64ConditionOptimizer.cpp
   AArch64RedundantCopyElimination.cpp
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -230,6 +230,7 @@
   initializeAArch64StackTaggingPass(*PR);
   initializeAArch64StackTaggingPreRAPass(*PR);
   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
+  initializeAArch64GlobalsTaggingPass(*PR);
 }
 
 //===--===//
@@ -579,6 +580,7 @@
 
   TargetPassConfig::addIRPasses();
 
+  addPass(createAArch64GlobalsTaggingPass());
   addPass(createAArch64StackTaggingPass(
   /*IsOptNone=*/TM->getOptLevel() == CodeGenOpt::None));
 
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -319,6 +319,13 @@
   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
 return AArch64II::MO_GOT;
 
+  // All globals dynamically protected by MTE must have their address tags
+  // synthesized. This is done by having the loader stash the tag in the GOT
+  // entry. Force all tagged globals (even ones with internal linkage) through
+  // the GOT.
+  if (GV->isTagged())
+return AArch64II::MO_GOT;
+
   if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
 if (GV->hasDLLImportStorageClass())
   return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT

[PATCH] D128958: Add assembler plumbing for sanitize_memtag

2022-09-01 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 457431.
hctim added a comment.
Herald added subscribers: cfe-commits, ormris, steven_wu.
Herald added a project: clang.

Move some existing stack tests to use -fsanitize=memtag-stack now that we have 
a non-android warning on -fsanitize=memtag-globals (which is implied by 
-fsantize=memtag, which the tests previously used).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128958/new/

https://reviews.llvm.org/D128958

Files:
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag-stack_lto.c
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/MC/MCSymbolELF.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCMachOStreamer.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCSymbolELF.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
  llvm/test/MC/AArch64/global-tagging.ll

Index: llvm/test/MC/AArch64/global-tagging.ll
===
--- /dev/null
+++ llvm/test/MC/AArch64/global-tagging.ll
@@ -0,0 +1,46 @@
+;; Tagged symbols are only available on aarch64-linux-android.
+; RUN: not llc %s -mtriple=aarch64-linux-unknown
+; RUN: not llc %s -mtriple=x86_64-linux-unknown
+
+; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
+; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
+; RUN: llvm-mc -filetype=obj %t.S -triple=aarch64-linux-android31 -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; RUN: obj2yaml %t.o -o %t.yaml
+; RUN: FileCheck %s --input-file=%t.yaml --check-prefix=CHECK-YAML
+; RUN: yaml2obj %t.yaml -o %t.o
+; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
+
+; CHECK-RELOCS: Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} internal_four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} four
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} sixteen
+; CHECK-RELOCS: R_AARCH64_NONE {{.*}} huge
+; CHECK-RELOCS-NOT: specialcaselisted
+
+; CHECK-YAML:  Sections:
+; CHECK-YAML:  - Name: .rela.memtag.globals.static
+; CHECK-YAML-NOT:  - Name:
+; CHECK-YAML:  Relocations:
+; CHECK-YAML-NEXT: - Symbol: internal_four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: four
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: sixteen
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: - Symbol: huge
+; CHECK-YAML-NEXT: Type: R_AARCH64_NONE
+; CHECK-YAML-NEXT: -
+
+; CHECK-ASM: .memtag internal_four
+; CHECK-ASM: .memtag four
+; CHECK-ASM: .memtag sixteen
+; CHECK-ASM: .memtag huge
+; CHECK-ASM-NOT: .memtag specialcaselisted
+
+@internal_four = internal global i32 1, sanitize_memtag
+@four = global i32 1, sanitize_memtag
+@sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
+@huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
+@specialcaselisted = global i16 2
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -34,6 +34,8 @@
 
   ~AArch64ELFObjectWriter() override = default;
 
+  MCSectionELF *getMemtagRelocsSection(MCContext &Ctx) const override;
+
 protected:
   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
 const MCFixup &Fixup, bool IsPCRel) const override;
@@ -453,6 +455,12 @@
   llvm_unreachable("Unimplemented fixup -> relocation");
 }
 
+MCSectionELF *
+AArch64ELFObjectWriter::getMemtagRelocsSection(MCContext &Ctx) const {
+  return Ctx.getELFSection(".memtag.globals.static",
+   ELF::SHT_ANDROID_MEMTAG_GLOBALS_STATIC, 0);
+}
+
 std::unique_ptr
 llvm::createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32) {
   return std::make_unique(OSABI, IsILP32);
Index: llvm/lib/MC/MCSymbolELF.cpp
===
--- llvm/lib/MC/MCSymbolELF.cpp
+++ llvm/lib/MC/MCSymbolELF.cpp
@@ -33,7 +33,10 @@
   ELF_WeakrefUsedInReloc_Shift = 11,
 
   // One bit.
-  ELF_BindingSet_Shift = 12
+  ELF_BindingSet_Shift = 12,
+
+  // One bit.
+  ELF_IsMemoryTagged_Shift = 13,
 };
 }
 
@@ -193,4 +196,16 @@
 bool MCSymbolELF::isBindingSet() const {
   return getFlags() & (0x1 << ELF_BindingSet_Shift);
 }
+
+bool MCSymbolELF::isMemtag() const {
+  return getFlags() & (0x1 << ELF_IsMemoryTagged_Shift);
+}
+
+void MCSymbolELF::setMemtag(bool Tagged) {
+  uint32_t OtherFlags = getFlags() & ~(1 << ELF_IsMemoryTagged_Shift);
+  if (Tagged)
+setFlags(OtherFlags | (1 << ELF_

[PATCH] D132425: [clang] Do not instrument relative vtables under hwasan

2022-08-26 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D132425#3753065 , @leonardchan 
wrote:

> We have a generic long term solution for hwasan+RV which I think might also 
> be applicable for MTE+RV. For hwasan, since it's mainly the IR pass that 
> converts usages of the vtable (within the vtable itself) to use tagged 
> aliases, the ideal solution is to just have hwasan ignore these specific 
> references in the vtable such that offset calculation can continue to use the 
> untagged address allowing the relocation arithmetic to not overflow. Now for 
> llvm, I'm assuming it's an instrumentation pass like memtagsanitizer that 
> will ensure all references to globals go through the GOT by replacing all 
> global references with the appropriate IR that gets lowered to this GOT 
> reference. If this is the case, then I *think* a similar solution can be done 
> here where particular references to the vtable continue to use the original 
> vtable address and avoid instrumentation.

HWASan and MTE have a nice invariant that helps - functions aren't tagged 
(phew). IIUC, For HWASan, it seems like you could just use an `_NC` relocation 
and truncate off the tag bits when materializing a function pointer from the 
relative vtable. For MTE, taking the address of the vtable would be indirect 
(as it has to be grabbed from the GOT), and applying the offset would result in 
a tagged function pointer. Because code pages aren't mapped as `PROT_MTE`, 
seems like this would succeed (maybe unwinders would have to be taught to 
truncate any tag bits, but that seems about it).

Either way, I don't think we should worry about it right this instant, and any 
problems would be easily detected during experimentation.

Didn't actually realise this was submitted. Appreciate the follow-up patch for 
non-relative-vtables + hwasan :).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132425/new/

https://reviews.llvm.org/D132425

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132425: [clang] Do not instrument relative vtables under hwasan

2022-08-26 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Glad to see that refactoring the sanitizer metadata made someone's life easier 
;) (now allowing for disabling hwasanificiation of globals)

Patch looks reasonable to me. Can you please add the negative test (that 
vtables under the vanilla ABI still have hwasan)?

I wans't fully aware of the relative vtables ABI, and it may have some 
implications about MTE globals tagging (draft abi 
).
 Because logical tags are synthesized at runtime into a synthetic GOT entry - 
dynamic relocations I believe would be forced (removing any benefit of the 
relative vtables ABI), so for now it seems like MTE globals and relative 
vtables are mutually exclusive. Another option would be to disable MTE globals 
for relative vtables as well. No action needed on your part, just putting some 
wordso n paper that this might need some consideration at a later date if 
Fuchsia wants to support MTE globals.




Comment at: 
clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-hwasan.cpp:1
+// RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -S -o - -emit-llvm 
-fsanitize=hwaddress | FileCheck %s
+

Can you add a note here that `-triple=aarch64-unknown-fuchsia` has implicit 
relative vtables


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132425/new/

https://reviews.llvm.org/D132425

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131806: Update hwasan test to fix failure on older Android API versions.

2022-08-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Thanks for the patch!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131806/new/

https://reviews.llvm.org/D131806

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-14 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D129048#3652689 , @aaron.ballman 
wrote:

> In D129048#3652679 , @hctim wrote:
>
>> Looks like unfortunately this breaks all lots of libcxx tests - which were 
>> picked up by our sanitizer buildbots:
>
> Thanks for letting us know.  Do you happen to know if there's any particular 
> reason why no email was sent out for the build failure?

No, sorry. Did it not get sent to `codesbyus...@gmail.com`? I see you committed 
it, but their address is the author of the commit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129048/new/

https://reviews.llvm.org/D129048

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-14 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Looks like unfortunately this breaks all lots of libcxx tests - which were 
picked up by our sanitizer buildbots:

https://lab.llvm.org/buildbot/#/builders/85/builds/9157

Should be reproducible with just `cmake 
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" && make check-cxx`.

An example:

   TEST 'llvm-libc++-shared.cfg.in :: 
std/utilities/format/format.formatter/format.parse.ctx/ch
  eck_arg_id.verify.cpp' FAILED 
   
  Script:   
   
  --
   
  : 'COMPILED WITH';  /llvm-build/opt/./bin/clang++ /llvm
  
/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/check_arg_id.verify.cpp
  --target=x86_64-unkn
  own-linux-gnu -nostdinc++ -I /llvm-build/opt/include/c++/v1 -I 
/llvm-build/opt/include/x86_64-unknown-linux-gnu/c++/v1 -I /llvm/libcxx/test
  /support -std=c++2b -Werror -Wall -Wextra -Wshadow -Wundef 
-Wno-unused-command-line-argument -Wno-attributes -Wno
  -pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type 
-Wno-atomic-alignment -Wno-user-defined-literals -Wno-
  tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter 
-Wunreachable-code -Wno-unused-local-typ
  edef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL 
-D_LIBCPP_DISABLE_AVAILABILITY -fcorouti
  nes-ts -Werror=thread-safety -Wuser-defined-warnings  -fsyntax-only 
-Wno-error -Xclang -verify -Xclang -verify-ig
  nore-unexpected=note -ferror-limit=0  
   
  --
   
  Exit Code: 1  
   

   
  Command Output (stdout):  
   
  --
   
  $ ":" "COMPILED WITH" 
   
  $ "/llvm-build/opt/./bin/clang++" "/llvm/libcxx/test/st
  d/utilities/format/format.formatter/format.parse.ctx/check_arg_id.verify.cpp" 
"--target=x86_64-unknown-linux-gnu"
   "-nostdinc++" "-I" "/llvm-build/opt/include/c++/v1" "-I" 
"/llvm-build/opt/include/x86_64-unknown-linux-gnu/c++/v1" "-I" 
"/llvm/libcxx/test
  /support" "-std=c++2b" "-Werror" "-Wall" "-Wextra" "-Wshadow" "-Wundef" 
"-Wno-unused-command-line-argument" "-Wno
  -attributes" "-Wno-pessimizing-move" "-Wno-c++11-extensions" 
"-Wno-noexcept-type" "-Wno-atomic-alignment" "-Wno-u
  ser-defined-literals" "-Wno-tautological-compare" "-Wsign-compare" 
"-Wunused-variable" "-Wunused-parameter" "-Wun
  reachable-code" "-Wno-unused-local-typedef" 
"-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER" "-D_LIBCPP_ENABLE_EXPERIMENTA
  L" "-D_LIBCPP_DISABLE_AVAILABILITY" "-fcoroutines-ts" "-Werror=thread-safety" 
"-Wuser-defined-warnings" "-fsyntax
  -only" "-Wno-error" "-Xclang" "-verify" "-Xclang" 
"-verify-ignore-unexpected=note" "-ferror-limit=0" 
  # command stderr: 
   
  error: 'error' diagnostics expected but not seen: 
   
File 
llvm/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/chec
  k_arg_id.verify.cpp Line 29: static assertion expression is not an integral 
constant expression  
  2 errors generated.   
   

   
  error: command failed with exit status: 1 
   

   
  --
   


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129048/new/

https://reviews.llvm.org/D129048

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129492: Add missing sanitizer metadata plumbing from CFE.

2022-07-13 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7045519359de: Add missing sanitizer metadata plumbing from 
CFE. (authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129492/new/

https://reviews.llvm.org/D129492

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp

Index: clang/test/CodeGen/memtag-globals.cpp
===
--- clang/test/CodeGen/memtag-globals.cpp
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -11,10 +11,12 @@
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
@@ -29,6 +31,7 @@
 
 // CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag
 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}} sanitize_memtag
 
 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 
@@ -44,3 +47,5 @@
 // IGNORELIST-NOT: sanitize_memtag
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}
 // IGNORELIST-NOT: sanitize_memtag
+// IGNORELIST: @{{.*}}external_global{{.*}} =
+// IGNORELIST-NOT: sanitize_memtag
Index: clang/test/CodeGen/hwasan-globals.cpp
===
--- clang/test/CodeGen/hwasan-globals.cpp
+++ clang/test/CodeGen/hwasan-globals.cpp
@@ -14,15 +14,18 @@
 int __attribute__((no_sanitize("hwaddress"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int __attribute__((no_sanitize("hwaddress"))) external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}extra_global{{.*}}.hwasan{{.*}} =
 // CHECK: @{{.*}}global{{.*}}.hwasan{{.*}} =
 // CHECK: @{{.*}}static_var{{.*}}.hwasan{{.*}} =
@@ -34,4 +37,5 @@
 // IGNORELIST: @{{.*}}ignorelisted_globa{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}, no_sanitize_hwaddress
+// IGNORELIST: @{{.*}}external_global{{.*}} ={{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}extra_global{{.*}}.hwasan{{.*}} =
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -12,6 +12,7 @@
 int __attribute__((no_sanitize("address"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int __attribute__((no_sanitize("address"))) external_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
 extern "C" {
@@ -21,6 +22,7 @@
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // GLOBS: @{{.*}}extra_global{{.*}} ={{.*}} global
@@ -49,6 +51,8 @@
 // GLOBS: @{{.*}} = {{.*}}c"Hello, world!\00"
 // GLOBS-NOT: no_sanitize_address
 
+// GLOBS: @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address
+
 /// Without -fasynchronous-unwind-tables, ctor and dtor get the uwtable attribute.
 // CHECK-LABEL: define internal void @asan.module_ctor() #[[#ATTR:]] {
 // ASAN-NEXT: call void @__asan_init
@@ -83,3 +87,4 @@
 // IGNORELIST-SRC: @{{.*}}__special_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address
 // IGNORELIST-SRC: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}} no_sanitize_address
 // IGNORELIST-SRC: @{{.*}} ={{.*}} c"Hello, world!\00"{{.*}} no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4293,6 +4293,9 @@
   getCUDARuntime().handleVarRegistration(D, *GV);
   }
 
+  if (D)
+SanitizerMD->reportGlobal(GV, *D);
+
   LangAS ExpectedAS =
   D ? D->getType().getAddressSpac

[PATCH] D128950: Remove 'no_sanitize_memtag'. Add 'sanitize_memtag'.

2022-07-13 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90e5a8ac475f: Remove 'no_sanitize_memtag'. Add 
'sanitize_memtag'. (authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128950/new/

https://reviews.llvm.org/D128950

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/globalvariable-attributes.ll
  llvm/test/Bitcode/compatibility.ll

Index: llvm/test/Bitcode/compatibility.ll
===
--- llvm/test/Bitcode/compatibility.ll
+++ llvm/test/Bitcode/compatibility.ll
@@ -206,14 +206,16 @@
 ; Global Variables -- sanitizers
 @g.no_sanitize_address = global i32 0, no_sanitize_address
 @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-@g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+@g.sanitize_memtag = global i32 0, sanitize_memtag
+@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+@g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 ; CHECK: @g.no_sanitize_address = global i32 0, no_sanitize_address
 ; CHECK: @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-; CHECK: @g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+; CHECK: @g.sanitize_memtag = global i32 0, sanitize_memtag
+; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 ; CHECK: @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+; CHECK: @g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 
 ;; Aliases
 ; Format: @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
Index: llvm/test/Assembler/globalvariable-attributes.ll
===
--- llvm/test/Assembler/globalvariable-attributes.ll
+++ llvm/test/Assembler/globalvariable-attributes.ll
@@ -6,9 +6,9 @@
 @g4 = global i32 2, align 4 "key5" = "value5" #0
 @g5 = global i32 2, no_sanitize_address, align 4
 @g6 = global i32 2, no_sanitize_hwaddress, align 4
-@g7 = global i32 2, no_sanitize_memtag, align 4
-@g8 = global i32 2, sanitize_address_dyninit, align 4
-@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+@g7 = global i32 2, sanitize_address_dyninit, align 4
+@g8 = global i32 2, sanitize_memtag, align 4
+@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 attributes #0 = { "string" = "value" nobuiltin norecurse }
 
@@ -18,9 +18,9 @@
 ; CHECK: @g4 = global i32 2, align 4 #3
 ; CHECK: @g5 = global i32 2, no_sanitize_address, align 4
 ; CHECK: @g6 = global i32 2, no_sanitize_hwaddress, align 4
-; CHECK: @g7 = global i32 2, no_sanitize_memtag, align 4
-; CHECK: @g8 = global i32 2, sanitize_address_dyninit, align 4
-; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+; CHECK: @g7 = global i32 2, sanitize_address_dyninit, align 4
+; CHECK: @g8 = global i32 2, sanitize_memtag, align 4
+; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 ; CHECK: attributes #0 = { "key"="value" "key2"="value2" }
 ; CHECK: attributes #1 = { "key3"="value3" }
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -3538,8 +3538,8 @@
   Out << ", no_sanitize_address";
 if (MD.NoHWAddress)
   Out << ", no_sanitize_hwaddress";
-if (MD.NoMemtag)
-  Out << ", no_sanitize_memtag";
+if (MD.Memtag)
+  Out << ", sanitize_memtag";
 if (MD.IsDynInit)
   Out << ", sanitize_address_dyninit";
   }
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1234,7 +1234,7 @@
 static unsigned
 serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) {
   return Meta.NoAddress | (Meta.NoHWAddress << 1) |
- (Meta.NoMemtag << 2) | (Meta.IsDynInit << 3);
+ (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
 }
 
 /// Emit top-level description of m

[PATCH] D129492: Add missing sanitizer metadata plumbing from CFE.

2022-07-12 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 444115.
hctim added a comment.

Update ASan and HWASan tests as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129492/new/

https://reviews.llvm.org/D129492

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp

Index: clang/test/CodeGen/memtag-globals.cpp
===
--- clang/test/CodeGen/memtag-globals.cpp
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -11,10 +11,12 @@
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
@@ -29,6 +31,7 @@
 
 // CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag
 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}} sanitize_memtag
 
 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 
@@ -44,3 +47,5 @@
 // IGNORELIST-NOT: sanitize_memtag
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}
 // IGNORELIST-NOT: sanitize_memtag
+// IGNORELIST: @{{.*}}external_global{{.*}} =
+// IGNORELIST-NOT: sanitize_memtag
Index: clang/test/CodeGen/hwasan-globals.cpp
===
--- clang/test/CodeGen/hwasan-globals.cpp
+++ clang/test/CodeGen/hwasan-globals.cpp
@@ -14,15 +14,18 @@
 int __attribute__((no_sanitize("hwaddress"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int __attribute__((no_sanitize("hwaddress"))) external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}extra_global{{.*}}.hwasan{{.*}} =
 // CHECK: @{{.*}}global{{.*}}.hwasan{{.*}} =
 // CHECK: @{{.*}}static_var{{.*}}.hwasan{{.*}} =
@@ -34,4 +37,5 @@
 // IGNORELIST: @{{.*}}ignorelisted_globa{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}, no_sanitize_hwaddress
+// IGNORELIST: @{{.*}}external_global{{.*}} ={{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}extra_global{{.*}}.hwasan{{.*}} =
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -12,6 +12,7 @@
 int __attribute__((no_sanitize("address"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int __attribute__((no_sanitize("address"))) external_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
 extern "C" {
@@ -21,6 +22,7 @@
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // GLOBS: @{{.*}}extra_global{{.*}} ={{.*}} global
@@ -49,6 +51,8 @@
 // GLOBS: @{{.*}} = {{.*}}c"Hello, world!\00"
 // GLOBS-NOT: no_sanitize_address
 
+// GLOBS: @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address
+
 /// Without -fasynchronous-unwind-tables, ctor and dtor get the uwtable attribute.
 // CHECK-LABEL: define internal void @asan.module_ctor() #[[#ATTR:]] {
 // ASAN-NEXT: call void @__asan_init
@@ -83,3 +87,4 @@
 // IGNORELIST-SRC: @{{.*}}__special_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address
 // IGNORELIST-SRC: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}} no_sanitize_address
 // IGNORELIST-SRC: @{{.*}} ={{.*}} c"Hello, world!\00"{{.*}} no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4289,6 +4289,9 @@
   getCUDARuntime().handleVarRegistration(D, *GV);
   }
 
+  if (D)
+SanitizerMD->reportGlobal(GV, *D);
+
   LangAS ExpectedAS =
   D ? D->getType().getAddressSpace()
 : (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Defaul

[PATCH] D128950: Remove 'no_sanitize_memtag'. Add 'sanitize_memtag'.

2022-07-12 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 444111.
hctim marked an inline comment as done.
hctim added a comment.

Final comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128950/new/

https://reviews.llvm.org/D128950

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/globalvariable-attributes.ll
  llvm/test/Bitcode/compatibility.ll

Index: llvm/test/Bitcode/compatibility.ll
===
--- llvm/test/Bitcode/compatibility.ll
+++ llvm/test/Bitcode/compatibility.ll
@@ -206,14 +206,16 @@
 ; Global Variables -- sanitizers
 @g.no_sanitize_address = global i32 0, no_sanitize_address
 @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-@g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+@g.sanitize_memtag = global i32 0, sanitize_memtag
+@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+@g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 ; CHECK: @g.no_sanitize_address = global i32 0, no_sanitize_address
 ; CHECK: @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-; CHECK: @g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+; CHECK: @g.sanitize_memtag = global i32 0, sanitize_memtag
+; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 ; CHECK: @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+; CHECK: @g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 
 ;; Aliases
 ; Format: @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
Index: llvm/test/Assembler/globalvariable-attributes.ll
===
--- llvm/test/Assembler/globalvariable-attributes.ll
+++ llvm/test/Assembler/globalvariable-attributes.ll
@@ -6,9 +6,9 @@
 @g4 = global i32 2, align 4 "key5" = "value5" #0
 @g5 = global i32 2, no_sanitize_address, align 4
 @g6 = global i32 2, no_sanitize_hwaddress, align 4
-@g7 = global i32 2, no_sanitize_memtag, align 4
-@g8 = global i32 2, sanitize_address_dyninit, align 4
-@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+@g7 = global i32 2, sanitize_address_dyninit, align 4
+@g8 = global i32 2, sanitize_memtag, align 4
+@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 attributes #0 = { "string" = "value" nobuiltin norecurse }
 
@@ -18,9 +18,9 @@
 ; CHECK: @g4 = global i32 2, align 4 #3
 ; CHECK: @g5 = global i32 2, no_sanitize_address, align 4
 ; CHECK: @g6 = global i32 2, no_sanitize_hwaddress, align 4
-; CHECK: @g7 = global i32 2, no_sanitize_memtag, align 4
-; CHECK: @g8 = global i32 2, sanitize_address_dyninit, align 4
-; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+; CHECK: @g7 = global i32 2, sanitize_address_dyninit, align 4
+; CHECK: @g8 = global i32 2, sanitize_memtag, align 4
+; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 ; CHECK: attributes #0 = { "key"="value" "key2"="value2" }
 ; CHECK: attributes #1 = { "key3"="value3" }
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -3538,8 +3538,8 @@
   Out << ", no_sanitize_address";
 if (MD.NoHWAddress)
   Out << ", no_sanitize_hwaddress";
-if (MD.NoMemtag)
-  Out << ", no_sanitize_memtag";
+if (MD.Memtag)
+  Out << ", sanitize_memtag";
 if (MD.IsDynInit)
   Out << ", sanitize_address_dyninit";
   }
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1232,7 +1232,7 @@
 static unsigned
 serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) {
   return Meta.NoAddress | (Meta.NoHWAddress << 1) |
- (Meta.NoMemtag << 2) | (Meta.IsDynInit << 3);
+ (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
 }
 
 /// Emit top-level description of module, including target triple, inline asm,
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===

[PATCH] D128672: Update DynInit generation for ASan globals.

2022-07-11 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf18de7619e5d: Update DynInit generation for ASan globals. 
(authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128672/new/

https://reviews.llvm.org/D128672

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off 
llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
+   FsanitizeArgument.has(SanitizerKind::Address) &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
+   FsanitizeArgument.has(SanitizerKind::Address) &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128672: Update DynInit generation for ASan globals.

2022-07-11 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 443702.
hctim marked an inline comment as done.
hctim added a comment.

Integrate Vitaly's suggestion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128672/new/

https://reviews.llvm.org/D128672

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off 
llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
+   FsanitizeArgument.has(SanitizerKind::Address) &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
+   FsanitizeArgument.has(SanitizerKind::Address) &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129492: Add missing sanitizer metadata plumbing from CFE.

2022-07-11 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: eugenis.
Herald added a project: All.
hctim requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang misses attaching sanitizer metadata for external globals.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129492

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/memtag-globals.cpp


Index: clang/test/CodeGen/memtag-globals.cpp
===
--- clang/test/CodeGen/memtag-globals.cpp
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -11,10 +11,12 @@
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;
 int ignorelisted_global;
+extern int external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
@@ -29,6 +31,7 @@
 
 // CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag
 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}} sanitize_memtag
 
 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 
@@ -44,3 +47,5 @@
 // IGNORELIST-NOT: sanitize_memtag
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}
 // IGNORELIST-NOT: sanitize_memtag
+// IGNORELIST: @{{.*}}external_global{{.*}} =
+// IGNORELIST-NOT: sanitize_memtag
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4286,6 +4286,9 @@
   getCUDARuntime().handleVarRegistration(D, *GV);
   }
 
+  if (D)
+SanitizerMD->reportGlobal(GV, *D);
+
   LangAS ExpectedAS =
   D ? D->getType().getAddressSpace()
 : (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Default);


Index: clang/test/CodeGen/memtag-globals.cpp
===
--- clang/test/CodeGen/memtag-globals.cpp
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -11,10 +11,12 @@
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
@@ -29,6 +31,7 @@
 
 // CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag
 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}} sanitize_memtag
 
 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 
@@ -44,3 +47,5 @@
 // IGNORELIST-NOT: sanitize_memtag
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}
 // IGNORELIST-NOT: sanitize_memtag
+// IGNORELIST: @{{.*}}external_global{{.*}} =
+// IGNORELIST-NOT: sanitize_memtag
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4286,6 +4286,9 @@
   getCUDARuntime().handleVarRegistration(D, *GV);
   }
 
+  if (D)
+SanitizerMD->reportGlobal(GV, *D);
+
   LangAS ExpectedAS =
   D ? D->getType().getAddressSpace()
 : (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Default);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128950: Add 'sanitize_memtag' Global IR attribute

2022-07-08 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 443390.
hctim added a comment.
Herald added subscribers: cfe-commits, ormris, steven_wu.
Herald added a project: clang.

After talking with Evgenii offline, and testing, clearly we don't need an 
exclude mask. Update the patch to remove the exclude mask, and replace it with 
an include mask.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128950/new/

https://reviews.llvm.org/D128950

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/globalvariable-attributes.ll
  llvm/test/Bitcode/compatibility.ll

Index: llvm/test/Bitcode/compatibility.ll
===
--- llvm/test/Bitcode/compatibility.ll
+++ llvm/test/Bitcode/compatibility.ll
@@ -206,14 +206,16 @@
 ; Global Variables -- sanitizers
 @g.no_sanitize_address = global i32 0, no_sanitize_address
 @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-@g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+@g.sanitize_memtag = global i32 0, sanitize_memtag
+@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+@g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 ; CHECK: @g.no_sanitize_address = global i32 0, no_sanitize_address
 ; CHECK: @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-; CHECK: @g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+; CHECK: @g.sanitize_memtag = global i32 0, sanitize_memtag
+; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 ; CHECK: @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+; CHECK: @g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 
 ;; Aliases
 ; Format: @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
Index: llvm/test/Assembler/globalvariable-attributes.ll
===
--- llvm/test/Assembler/globalvariable-attributes.ll
+++ llvm/test/Assembler/globalvariable-attributes.ll
@@ -6,9 +6,9 @@
 @g4 = global i32 2, align 4 "key5" = "value5" #0
 @g5 = global i32 2, no_sanitize_address, align 4
 @g6 = global i32 2, no_sanitize_hwaddress, align 4
-@g7 = global i32 2, no_sanitize_memtag, align 4
-@g8 = global i32 2, sanitize_address_dyninit, align 4
-@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+@g7 = global i32 2, sanitize_address_dyninit, align 4
+@g8 = global i32 2, sanitize_memtag, align 4
+@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 attributes #0 = { "string" = "value" nobuiltin norecurse }
 
@@ -18,9 +18,9 @@
 ; CHECK: @g4 = global i32 2, align 4 #3
 ; CHECK: @g5 = global i32 2, no_sanitize_address, align 4
 ; CHECK: @g6 = global i32 2, no_sanitize_hwaddress, align 4
-; CHECK: @g7 = global i32 2, no_sanitize_memtag, align 4
-; CHECK: @g8 = global i32 2, sanitize_address_dyninit, align 4
-; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+; CHECK: @g7 = global i32 2, sanitize_address_dyninit, align 4
+; CHECK: @g8 = global i32 2, sanitize_memtag, align 4
+; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 ; CHECK: attributes #0 = { "key"="value" "key2"="value2" }
 ; CHECK: attributes #1 = { "key3"="value3" }
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -3542,8 +3542,8 @@
   Out << ", no_sanitize_address";
 if (MD.NoHWAddress)
   Out << ", no_sanitize_hwaddress";
-if (MD.NoMemtag)
-  Out << ", no_sanitize_memtag";
+if (MD.Memtag)
+  Out << ", sanitize_memtag";
 if (MD.IsDynInit)
   Out << ", sanitize_address_dyninit";
   }
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1230,7 +1230,7 @@
 static unsigned
 serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) {
   return Meta.NoAddress | (Meta.NoHWAddress << 1) |
- (Meta.NoMemtag << 2) | (Meta.IsDynInit << 3);
+ 

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-28 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127911#3614242 , @thakis wrote:

> Looks like this breaks check-clang on windows: 
> http://45.33.8.238/win/61067/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

Thanks. Added a2095d1aff84 
. Bot 
looks green now: http://45.33.8.238/win/61118/summary.html


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-27 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hctim marked an inline comment as done.
Closed by commit rGdacfa24f75c3: Delete 'llvm.asan.globals' for 
global metadata. (authored by hctim).

Changed prior to commit:
  https://reviews.llvm.org/D127911?vs=439918&id=440404#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='as

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-27 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 3 inline comments as done.
hctim added inline comments.



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:67-72
+  if (FsanitizeArgument.has(SanitizerKind::Address) && !Meta.NoAddress) {
 IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
  SanitizerKind::KernelAddress,
  GV, Loc, Ty, "init");
 Meta.IsDynInit = IsDynInit;
   }

hctim wrote:
> vitalybuka wrote:
> > I recommend to move this change into another patch
> > 
> > and it should probably be:
> > Meta.IsDynInit &= IsDynInit && 
> > FsanitizeArgument.has(SanitizerKind::Address) && !Meta.NoAddress && 
> > !CGM.isInNoSanitizeLis;
> sure, will punt to follow-up patch (leaving comment open, will close it out 
> when i've added the dependency)
(punted to D128672)



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1355-1356
   // at all, we assume it has dynamic initializer (in other TU).
-  //
-  // FIXME: Metadata should be attched directly to the global directly instead
-  // of being added to llvm.asan.globals.
-  return G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
+  if (G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)
+return false;
+

vitalybuka wrote:
> vitalybuka wrote:
> > hctim wrote:
> > > vitalybuka wrote:
> > > > I believe previous was like this.
> > > > if you want to change that lets do another patch. 
> > > refactored it slightly, it's clear to me now (and IMHO much clearer to 
> > > reason about, i suck at flipping multiple conditions in my head) that 
> > > it's the same code
> > Before: G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
> > Now:  G->hasInitializer() && !(G->hasSanitizerMetadata() && 
> > G->getSanitizerMetadata().IsDynInit)
> > 
> > Which is fine, because previously NoMD == !IsDynInit
> > 
> > So logic-wise this version is LGTM
> > equivalent one-liner is even cleaner:
> > return G->hasInitializer() && !(G->hasSanitizerMetadata() && 
> > G->getSanitizerMetadata().IsDynInit)
> > Before: G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
> "Before" is "Before the patch"
> 
I personally find the multi-liner much easier to read than the one-liner, okay 
to leave?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128672: Update DynInit generation for ASan globals.

2022-06-27 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: vitalybuka.
Herald added a project: All.
hctim requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Address a follow-up TODO for Sanitizer Metadata.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128672

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off 
llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = FsanitizeArgument.has(SanitizerKind::Address) && IsDynInit 
&&
+   !Meta.NoAddress &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = FsanitizeArgument.has(SanitizerKind::Address) && IsDynInit &&
+   !Meta.NoAddress &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 439918.
hctim marked 3 inline comments as done.
hctim added a comment.

Vitaly's comments, round 2.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='asan-pipeline' -asan-mapping-scale=5 -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 tar

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:67-72
+  if (FsanitizeArgument.has(SanitizerKind::Address) && !Meta.NoAddress) {
 IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
  SanitizerKind::KernelAddress,
  GV, Loc, Ty, "init");
 Meta.IsDynInit = IsDynInit;
   }

vitalybuka wrote:
> I recommend to move this change into another patch
> 
> and it should probably be:
> Meta.IsDynInit &= IsDynInit && FsanitizeArgument.has(SanitizerKind::Address) 
> && !Meta.NoAddress && !CGM.isInNoSanitizeLis;
sure, will punt to follow-up patch (leaving comment open, will close it out 
when i've added the dependency)



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:34
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/Argument.h"

vitalybuka wrote:
> Please don't demangle in this patch, or keep as close as possible to the 
> current behaviour
> Also isn't demangling by compliler-rt is better? mangled form is shorter.
as discussed, current descriptor has the demangled name because it's provided 
by clang frontend in `llvm.asan.globals`.

to keep this migration as close to the original as possible, keeping demangle 
of names in descriptors here, but added a TODO for follow-up work to instead 
demangle in the runtime.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1355-1356
   // at all, we assume it has dynamic initializer (in other TU).
-  //
-  // FIXME: Metadata should be attched directly to the global directly instead
-  // of being added to llvm.asan.globals.
-  return G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
+  if (G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)
+return false;
+

vitalybuka wrote:
> I believe previous was like this.
> if you want to change that lets do another patch. 
refactored it slightly, it's clear to me now (and IMHO much clearer to reason 
about, i suck at flipping multiple conditions in my head) that it's the same 
code


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 439912.
hctim marked 2 inline comments as done.
hctim added a comment.

Vitaly's comments - round 1.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='asan-pipeline' -asan-mapping-scale=5 -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 ta

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 2 inline comments as done.
hctim added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2100
+GlobalVariable *Metadata = CreateMetadataGlobal(
+M, Initializer, llvm::demangle(std::string(G->getName(;
 

vitalybuka wrote:
> was this demanded before?
removed, think this got accidentally added during a sweep of demangling names 
for the produced metadata, which is necessary now that clang doesn't produce 
the info.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2330
+ConstantInt::get(IntptrTy, Meta.IsDynInit),
+ConstantInt::get(IntptrTy, 0),
 ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));

vitalybuka wrote:
> MD was fine, less changed lines
done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

I see that the clang-ppc64le-linux bot is green with the second attempt 
(https://lab.llvm.org/buildbot/#/builders/105/builds/27200). Please let me know 
if you have further issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127544#3609343 , 
@hubert.reinterpretcast wrote:

> In D127544#3609335 , @hctim wrote:
>
>> Sent fadc98b06befb674fa47da4f3d8606bf61bed681 
>>  to 
>> fix-forward.
>
> I thought `*-registered-target` is true as long as the target is available, 
> not only when the target happens to be the default.
> Also, if there would be more such tests in the future, maybe a LIT feature 
> that the default target supports HWAsan makes sense?

Too right. Given the purpose of this test is to just check that the globals 
have the right IR attributes, any target is fine - as the IR attributes aren't 
target-specific.

Took another fix-forward whack-a-mole attempt, committing in a sec.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Sent fadc98b06befb674fa47da4f3d8606bf61bed681 
 to 
fix-forward.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127544#3609312 , 
@hubert.reinterpretcast wrote:

> This is causing "unsupported architecture" errors on bots.

Looking, I see this on the sanitizer-ppc64 bots.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 439880.
hctim added a comment.

Rebase on main / landed changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='asan-pipeline' -asan-mapping-scale=5 -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-unknown-linux-

[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfaf5e0ec737a: Add no_sanitize('hwaddress') (and 
'memtag', but that's a no-op). (authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/Inputs/sanitizer-extra-source.cpp
  clang/test/CodeGen/Inputs/sanitizer-ignorelist-global.txt
  clang/test/CodeGen/Inputs/sanitizer-ignorelist-src.txt
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  compiler-rt/test/hwasan/TestCases/global-with-reduction.c
  compiler-rt/test/hwasan/TestCases/global.c

Index: compiler-rt/test/hwasan/TestCases/global.c
===
--- compiler-rt/test/hwasan/TestCases/global.c
+++ compiler-rt/test/hwasan/TestCases/global.c
@@ -14,9 +14,23 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
+#include 
+
+int a = 1;
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) int x = 1;
+#else // USE_NOSANITIZE
 int x = 1;
+#endif // USE_NOSANITIZE
+int b = 1;
 
 int atoi(const char *);
 
Index: compiler-rt/test/hwasan/TestCases/global-with-reduction.c
===
--- compiler-rt/test/hwasan/TestCases/global-with-reduction.c
+++ compiler-rt/test/hwasan/TestCases/global-with-reduction.c
@@ -14,20 +14,37 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
-int x = 1;
+#include 
 
-int atoi(const char *);
+// GlobalOpt may replace the current GV with a new boolean-typed GV. Previously,
+// this resulted in the "nosanitize" getting dropped because while the data/code
+// references to the GV were updated, the old metadata references weren't.
+int* f() {
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) static int x = 1;
+#else // USE_NOSANITIZE
+  static int x = 1;
+#endif // USE_NOSANITIZE
+  if (x == 1) x = 0;
+  return &x;
+}
 
 int main(int argc, char **argv) {
   // CHECK: Cause: global-overflow
-  // RSYM: is located 0 bytes to the right of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RSYM: is located 0 bytes to the right of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // RNOSYM: is located to the right of a 4-byte global variable in
-  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
-  // LSYM: is located 4 bytes to the left of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
+  // LSYM: is located 4 bytes to the left of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // LNOSYM: is located to the left of a 4-byte global variable in
-  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
+  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
   // CHECK-NOT: can not describe
-  (&x)[atoi(argv[1])] = 1;
+  f()[atoi(argv[1])] = 1;
 }
Index: clang/test/CodeGen/memtag-globals.cpp
===
--- /dev/null
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
+// RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
+// RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=IGNORELIST
+
+int global;
+int __attribute__((no_sanitize("memtag"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
+int ignorelisted_global;
+
+void func() {
+  static int static_var = 0;
+  const char *literal = "Hello, world!";
+}
+
+// CHECK: @{{.*}}extra_global{{.*}} =
+// CHECK-NOT: no_sanitize_memtag
+// CHECK: @{{.*}}glo

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-23 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127911#3605774 , @MaskRay wrote:

>> This saves about ~0.275% of the optimised clang binary.
>
> Worth clarifying a bit which -O level and whether -g is used.

`clang-15` binary, no `-g`, `-DLLVM_ENABLE_ASSERTIONS=ON 
-DCMAKE_BUILD_TYPE=Release`:

Before: 1041657808
After: 1024109680

Not sure what led to the original measurement, but seems like this saves ~1.7% 
of binary size for ASan. I'll update the description.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-23 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

friendly ping @vitalybuka


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 437734.
hctim marked 2 inline comments as done.
hctim added a comment.

Create test input files rather than synthesizing on the fly, fix tests on 
windows.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/Inputs/sanitizer-extra-source.cpp
  clang/test/CodeGen/Inputs/sanitizer-ignorelist-global.txt
  clang/test/CodeGen/Inputs/sanitizer-ignorelist-src.txt
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  compiler-rt/test/hwasan/TestCases/global-with-reduction.c
  compiler-rt/test/hwasan/TestCases/global.c

Index: compiler-rt/test/hwasan/TestCases/global.c
===
--- compiler-rt/test/hwasan/TestCases/global.c
+++ compiler-rt/test/hwasan/TestCases/global.c
@@ -14,9 +14,23 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
+#include 
+
+int a = 1;
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) int x = 1;
+#else // USE_NOSANITIZE
 int x = 1;
+#endif // USE_NOSANITIZE
+int b = 1;
 
 int atoi(const char *);
 
Index: compiler-rt/test/hwasan/TestCases/global-with-reduction.c
===
--- compiler-rt/test/hwasan/TestCases/global-with-reduction.c
+++ compiler-rt/test/hwasan/TestCases/global-with-reduction.c
@@ -14,20 +14,37 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
-int x = 1;
+#include 
 
-int atoi(const char *);
+// GlobalOpt may replace the current GV with a new boolean-typed GV. Previously,
+// this resulted in the "nosanitize" getting dropped because while the data/code
+// references to the GV were updated, the old metadata references weren't.
+int* f() {
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) static int x = 1;
+#else // USE_NOSANITIZE
+  static int x = 1;
+#endif // USE_NOSANITIZE
+  if (x == 1) x = 0;
+  return &x;
+}
 
 int main(int argc, char **argv) {
   // CHECK: Cause: global-overflow
-  // RSYM: is located 0 bytes to the right of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RSYM: is located 0 bytes to the right of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // RNOSYM: is located to the right of a 4-byte global variable in
-  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
-  // LSYM: is located 4 bytes to the left of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
+  // LSYM: is located 4 bytes to the left of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // LNOSYM: is located to the left of a 4-byte global variable in
-  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
+  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
   // CHECK-NOT: can not describe
-  (&x)[atoi(argv[1])] = 1;
+  f()[atoi(argv[1])] = 1;
 }
Index: clang/test/CodeGen/memtag-globals.cpp
===
--- /dev/null
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
+// RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
+// RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=IGNORELIST
+
+int global;
+int __attribute__((no_sanitize("memtag"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
+int ignorelisted_global;
+
+void func() {
+  static int static_var = 0;
+  const char *literal = "Hello, world!";
+}
+
+// CHECK: @{{.*}}extra_global{{.*}} =
+// CHECK-NOT: no_sanitize_memtag
+// CHECK: @{{.*}}global{{.*}} =
+// CHECK-NOT: no_sanitize_memtag
+// CHECK: 

[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 2 inline comments as done.
hctim added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8849
 break;
-  
   // HLSL attributes:

aaron.ballman wrote:
> hctim wrote:
> > aaron.ballman wrote:
> > > Spurious whitespace change?
> > unfortunately there's no way in my editor to trim trailing whitespace only 
> > on changed lines :(, so i end up fixing things like this drive-by.
> > 
> > let me know if you feel very strongly about this diff and I can kill it, 
> > but I personally think the drive-by-fix isn't a huge problem and the 
> > alternative of whitespace-fix-only commit seems a bit overkill
> Personally, I don't feel very strongly because the chances of the whitespace 
> being someone's entrypoint to git-blame is pretty minimal (especially given 
> there's only one change here). However, we typically still ask for formatting 
> changes to be separated out 
> (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access #2) 
> rather than lumped in with functional changes so reviewers will ask for these 
> sort of changes to be backed out, so this may crop up repeatedly if your 
> editor doesn't give you the options you need.
Fixed in ee28837a1fbd574dbec14b9f09cb4effab6a492a.



Comment at: clang/test/CodeGen/hwasan-globals.cpp:1-2
+// RUN: echo "int extra_global;" > %t.extra-source.cpp
+// RUN: echo "global:*ignorelisted_global*" > %t.ignorelist
+// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=hwaddress 
-fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK

aaron.ballman wrote:
> hctim wrote:
> > aaron.ballman wrote:
> > > Are these files automatically deleted when the test is done because we're 
> > > using %t, or do we need to clean those up manually?
> > AFAIK nothing is ever automatically deleted (e.g. the outputs of the 
> > compiler). Is automated cleanup here necessary?
> Necessary? Probably not (I'd expect these to go into the temp directory). A 
> kindness so disks don't fill up? Probably. Because the content here is static 
> anyway, these could just be files in the `Inputs` directory so they don't 
> need to be created every time the test is run.
Done (and also will update `asan-globals.cpp` when this lands to use the new 
files as well).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124493: Move Sanitizer metadata to be on-GlobalValue.

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim abandoned this revision.
hctim added a comment.
Herald added a subscriber: Enna1.

Integrated slowly and surely as part of the stack leading up to D127911 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124493/new/

https://reviews.llvm.org/D124493

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126224: Add DWARF string debug to clang release notes.

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG011e0604ebc9: Add DWARF string debug to clang release notes. 
(authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126224/new/

https://reviews.llvm.org/D126224

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -498,6 +498,13 @@
 DWARF Support in Clang
 --
 
+- clang now adds DWARF information for inline strings in C/C++ programs,
+  allowing ``line:column`` symbolization of strings. Some debugging programs 
may
+  require updating, as this takes advantage of DWARF ``DW_TAG_variable``
+  structures *without* a ``DW_AT_name`` field, which is valid DWARF, but may be
+  handled incorrectly by some software (e.g. new failures with incorrect
+  assertions).
+
 Arm and AArch64 Support in Clang
 
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -498,6 +498,13 @@
 DWARF Support in Clang
 --
 
+- clang now adds DWARF information for inline strings in C/C++ programs,
+  allowing ``line:column`` symbolization of strings. Some debugging programs may
+  require updating, as this takes advantage of DWARF ``DW_TAG_variable``
+  structures *without* a ``DW_AT_name`` field, which is valid DWARF, but may be
+  handled incorrectly by some software (e.g. new failures with incorrect
+  assertions).
+
 Arm and AArch64 Support in Clang
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126224: Add DWARF string debug to clang release notes.

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 437717.
hctim marked an inline comment as done.
hctim added a comment.

Change a small amount of wording, rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126224/new/

https://reviews.llvm.org/D126224

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -498,6 +498,13 @@
 DWARF Support in Clang
 --
 
+- clang now adds DWARF information for inline strings in C/C++ programs,
+  allowing ``line:column`` symbolization of strings. Some debugging programs 
may
+  require updating, as this takes advantage of DWARF ``DW_TAG_variable``
+  structures *without* a ``DW_AT_name`` field, which is valid DWARF, but may be
+  handled incorrectly by some software (e.g. new failures with incorrect
+  assertions).
+
 Arm and AArch64 Support in Clang
 
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -498,6 +498,13 @@
 DWARF Support in Clang
 --
 
+- clang now adds DWARF information for inline strings in C/C++ programs,
+  allowing ``line:column`` symbolization of strings. Some debugging programs may
+  require updating, as this takes advantage of DWARF ``DW_TAG_variable``
+  structures *without* a ``DW_AT_name`` field, which is valid DWARF, but may be
+  handled incorrectly by some software (e.g. new failures with incorrect
+  assertions).
+
 Arm and AArch64 Support in Clang
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126224: Add DWARF string debug to clang release notes.

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked an inline comment as done.
hctim added a comment.

In D126224#3534643 , @probinson wrote:

> I see some unrelated whitespace changes, we generally don't like mixing those 
> with "real" changes.  But the description seems fine to me.

Looks like someone has cleaned up the whitespace, so the diff is cleaner.




Comment at: clang/docs/ReleaseNotes.rst:447
+  structures *without* a ``DW_AT_name`` field, which is valid DWARF, but may
+  lead to assertion failures in some software.
+

paulkirth wrote:
> nit: its likely not an assertion failure, but just invalid code.
> 
> It's also fine w/ me to word this differently, or ignore the suggestion.
changed the wording - it's just a common case of "invalid code" that we've seen 
- asserting that DW_TAG_variables must have a DW_AT_name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126224/new/

https://reviews.llvm.org/D126224

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126224: Add DWARF string debug to clang release notes.

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

(thanks for the bump - this one fell off the radar)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126224/new/

https://reviews.llvm.org/D126224

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126224: Add DWARF string debug to clang release notes.

2022-06-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Yeah, I'll look at landing it today.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126224/new/

https://reviews.llvm.org/D126224

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 437385.
hctim added a comment.

Small test fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127911/new/

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='asan-pipeline' -asan-mapping-scale=5 -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-unknown-linux-gnu"
-@xxx = internal global i32 0, align 4  ; With dynamic initializer.
-@XXX 

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: vitalybuka.
Herald added subscribers: Enna1, ormris, hiraditya.
Herald added a project: All.
hctim requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

Now that we have the sanitizer metadata that is actually on the global
variable, and now that we use debuginfo in order to do symbolization of
globals, we can delete the 'llvm.asan.globals' IR synthesis.

This patch deletes the 'location' part of the __asan_global that's
embedded in the binary as well, because it's unnecessary. This saves
about ~0.275% of the optimised clang binary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/

[PATCH] D127163: [clang] Add -fsanitize=memtag-globals (no-op).

2022-06-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127163#3587115 , @thakis wrote:

> FYI: If you change serialized opts in a def file, you have to bump the pch 
> version, else with builds that don't embed the llvm revision 
> (LLVM_APPEND_VC_REV=OFF) won't notice they have to invalidate pchs.
>
> (In this case, I did this in 
> https://github.com/llvm/llvm-project/commit/307109266f6c7598dfc69b6388fa271662de9388
>  for this change.)

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127163/new/

https://reviews.llvm.org/D127163

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8849
 break;
-  
   // HLSL attributes:

aaron.ballman wrote:
> Spurious whitespace change?
unfortunately there's no way in my editor to trim trailing whitespace only on 
changed lines :(, so i end up fixing things like this drive-by.

let me know if you feel very strongly about this diff and I can kill it, but I 
personally think the drive-by-fix isn't a huge problem and the alternative of 
whitespace-fix-only commit seems a bit overkill



Comment at: clang/test/CodeGen/hwasan-globals.cpp:1-2
+// RUN: echo "int extra_global;" > %t.extra-source.cpp
+// RUN: echo "global:*ignorelisted_global*" > %t.ignorelist
+// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=hwaddress 
-fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK

aaron.ballman wrote:
> Are these files automatically deleted when the test is done because we're 
> using %t, or do we need to clean those up manually?
AFAIK nothing is ever automatically deleted (e.g. the outputs of the compiler). 
Is automated cleanup here necessary?



Comment at: clang/test/CodeGen/hwasan-globals.cpp:9
+int global;
+int __attribute__((no_sanitize("hwaddress"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;

aaron.ballman wrote:
> Should we add a `memtag` test as well given that also changed in this patch?
sure, done



Comment at: compiler-rt/test/hwasan/TestCases/global-with-reduction.c:25
 
-int x = 1;
+#include 
 

aaron.ballman wrote:
> I'm not a compiler-rt expert, but is this valid? I assume this is using the 
> system stdlib.h which is not something we usually want in lit tests.
> 
> I think that's why `atoi` was previously being forward declared; then we 
> don't need to include the whole header file.
I don't see there being any problem with including stdlib.h here, it's done in 
lots of other compiler-rt tests.

I patched this up because the compiler actually complains about 
forward-declaring c library functions (it's just silenced by llvm-lit by 
default).



Comment at: compiler-rt/test/hwasan/TestCases/global-with-reduction.c:50
+  f()[atoi(argv[1])] = 1;
+  return 0;
 }

aaron.ballman wrote:
> This is unnecessary -- falling off `main` already returns 0.
sure, done



Comment at: compiler-rt/test/hwasan/TestCases/global.c:47
   (&x)[atoi(argv[1])] = 1;
+  return 0;
 }

aaron.ballman wrote:
> This is unnecessary -- falling off `main` already returns 0.
sure, done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 437355.
hctim marked 6 inline comments as done.
hctim added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127544/new/

https://reviews.llvm.org/D127544

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  compiler-rt/test/hwasan/TestCases/global-with-reduction.c
  compiler-rt/test/hwasan/TestCases/global.c

Index: compiler-rt/test/hwasan/TestCases/global.c
===
--- compiler-rt/test/hwasan/TestCases/global.c
+++ compiler-rt/test/hwasan/TestCases/global.c
@@ -14,9 +14,23 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
+#include 
+
+int a = 1;
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) int x = 1;
+#else // USE_NOSANITIZE
 int x = 1;
+#endif // USE_NOSANITIZE
+int b = 1;
 
 int atoi(const char *);
 
Index: compiler-rt/test/hwasan/TestCases/global-with-reduction.c
===
--- compiler-rt/test/hwasan/TestCases/global-with-reduction.c
+++ compiler-rt/test/hwasan/TestCases/global-with-reduction.c
@@ -14,20 +14,37 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
-int x = 1;
+#include 
 
-int atoi(const char *);
+// GlobalOpt may replace the current GV with a new boolean-typed GV. Previously,
+// this resulted in the "nosanitize" getting dropped because while the data/code
+// references to the GV were updated, the old metadata references weren't.
+int* f() {
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) static int x = 1;
+#else // USE_NOSANITIZE
+  static int x = 1;
+#endif // USE_NOSANITIZE
+  if (x == 1) x = 0;
+  return &x;
+}
 
 int main(int argc, char **argv) {
   // CHECK: Cause: global-overflow
-  // RSYM: is located 0 bytes to the right of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RSYM: is located 0 bytes to the right of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // RNOSYM: is located to the right of a 4-byte global variable in
-  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
-  // LSYM: is located 4 bytes to the left of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
+  // LSYM: is located 4 bytes to the left of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // LNOSYM: is located to the left of a 4-byte global variable in
-  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
+  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
   // CHECK-NOT: can not describe
-  (&x)[atoi(argv[1])] = 1;
+  f()[atoi(argv[1])] = 1;
 }
Index: clang/test/CodeGen/memtag-globals.cpp
===
--- /dev/null
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -0,0 +1,60 @@
+// RUN: echo "int extra_global;" > %t.extra-source.cpp
+// RUN: echo "global:*ignorelisted_global*" > %t.ignorelist
+// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=memtag-globals -fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK
+// The ignorelist file uses regexps, so Windows path backslashes.
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t.ignorelist-src
+// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=memtag-globals -fsanitize-ignorelist=%t.ignorelist-src -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST
+
+int global;
+int __attribute__((no_sanitize("memtag"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
+int ignorelisted_global;
+
+void func() {
+  static int static_var = 0;
+  const char *literal = "Hello, world!";
+}
+
+// CHECK: @{{.*}}extra_global{{.*}} =
+// CHECK-NOT: no_sanitize_memtag
+// CHECK: @{{.*}}global{{.*}} =
+// CHECK-NOT: no_sanitize_memtag
+// CHECK: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag
+// CHECK: @{{.*}}disable_instrumentation_global{{.*

[PATCH] D127163: [clang] Add -fsanitize=memtag-globals (no-op).

2022-06-15 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG45d88cd00846: [clang] Add -fsanitize=memtag-globals (no-op). 
(authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127163/new/

https://reviews.llvm.org/D127163

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -193,9 +193,9 @@
 // RUN: %clang -target x86_64-linux-android -fsanitize=memtag -fno-rtti %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-BAD-ARCH
 // CHECK-SANMT-BAD-ARCH: unsupported option '-fsanitize=memtag' for target
 
-// RUN: %clang -target aarch64-linux -fsanitize=memtag -march=armv8-a+memtag 
%s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-MT
+// RUN: %clang -target aarch64-linux-android31 -fsanitize=memtag 
-march=armv8-a+memtag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-MT
 // CHECK-SANMT-MT: "-target-feature" "+mte"
-// CHECK-SANMT-MT-SAME: "-fsanitize=memtag-stack,memtag-heap"
+// CHECK-SANMT-MT-SAME: "-fsanitize=memtag-stack,memtag-heap,memtag-globals"
 
 // RUN: %clang -target aarch64-linux -fsanitize=memtag %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-SANMT-NOMT-0
 // CHECK-SANMT-NOMT-0: '-fsanitize=memtag-stack' requires hardware support 
(+memtag)
@@ -827,7 +827,7 @@
 // CHECK-INTSAN-MINIMAL: "-fsanitize-minimal-runtime"
 
 // RUN: %clang -target aarch64-linux-android -march=armv8-a+memtag 
-fsanitize=memtag -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MEMTAG-MINIMAL
-// CHECK-MEMTAG-MINIMAL: "-fsanitize=memtag-stack,memtag-heap"
+// CHECK-MEMTAG-MINIMAL: "-fsanitize=memtag-stack,memtag-heap,memtag-globals"
 // CHECK-MEMTAG-MINIMAL: "-fsanitize-minimal-runtime"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
-fsanitize=function -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-UBSAN-FUNCTION-MINIMAL
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -45,7 +45,8 @@
 SanitizerKind::Address | SanitizerKind::HWAddress |
 SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress |
 SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap |
-SanitizerKind::Memory | SanitizerKind::KernelMemory | SanitizerKind::Leak |
+SanitizerKind::MemtagGlobals | SanitizerKind::Memory |
+SanitizerKind::KernelMemory | SanitizerKind::Leak |
 SanitizerKind::Undefined | SanitizerKind::Integer | SanitizerKind::Bounds |
 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
 SanitizerKind::DataFlow | SanitizerKind::Fuzzer |
@@ -73,7 +74,8 @@
 SanitizerKind::CFIUnrelatedCast;
 static const SanitizerMask CompatibleWithMinimalRuntime =
 TrappingSupported | SanitizerKind::Scudo | SanitizerKind::ShadowCallStack |
-SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap;
+SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap |
+SanitizerKind::MemtagGlobals;
 
 enum CoverageFeature {
   CoverageFunc = 1 << 0,
Index: clang/include/clang/Driver/SanitizerArgs.h
===
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -99,13 +99,18 @@
   bool needsStatsRt() const { return Stats; }
   bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
 
-  bool hasMemTag() const { return hasMemtagHeap() || hasMemtagStack(); }
+  bool hasMemTag() const {
+return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
+  }
   bool hasMemtagHeap() const {
 return Sanitizers.has(SanitizerKind::MemtagHeap);
   }
   bool hasMemtagStack() const {
 return Sanitizers.has(SanitizerKind::MemtagStack);
   }
+  bool hasMemtagGlobals() const {
+return Sanitizers.has(SanitizerKind::MemtagGlobals);
+  }
   const std::string &getMemtagMode() const {
 assert(!MemtagMode.empty());
 return MemtagMode;
Index: clang/include/clang/Basic/Sanitizers.def
===
--- clang/include/clang/Basic/Sanitizers.def
+++ clang/include/clang/Basic/Sanitizers.def
@@ -58,7 +58,8 @@
 // A variant of AddressSanitizer using AArch64 MTE extension.
 SANITIZER("memtag-stack", MemtagStack)
 SANITIZER("memtag-heap", MemtagHeap)
-SANITIZER_GROUP("memtag", MemTag, MemtagStack | MemtagHeap)
+SANITIZER("memtag-globals", MemtagGlobals)
+SANITIZER_GROUP("memtag", MemTag, MemtagStack | MemtagHeap | MemtagGlobals)
 
 // MemorySanit

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

LGTM: http://45.33.8.238/win/60042/summary.html


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Thanks for the heads up. Reverted, and now re-landing. Unfortunately I don't 
have a Windows machine so I've made my best guesses about fixing (mostly seems 
to just symbol name mangling / global attributes that change on the windows 
target). I'll keep an eye on that specific bot but please let me know if I need 
to continue to whack-a-mole.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-13 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7766972a679: Add sanitizer metadata attributes to clang IR 
gen. (authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/Inputs/sanitizer-special-case-list-globals.txt
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c

Index: clang/test/CodeGen/sanitizer-special-case-list-globals.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitizer-special-case-list-globals.c
@@ -0,0 +1,91 @@
+/// Verify that ignorelist sections correctly select sanitizers to apply
+/// ignorelist entries to.
+
+// RUN: %clang_cc1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Note: HWASan effectively reorders globals (it puts the unsanitized ones
+/// first), which is hard to check for, as 'CHECK-DAG' doesn't play terribly
+/// nicely with 'CHECK-NOT'. This is why the 'always_ignored' and
+/// 'hwasan_ignored' comes first in this file.
+// RUN: %clang_cc1 -fsanitize=hwaddress -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=HWASAN
+
+/// TODO(hctim): Move over to memtag-globals when it's implemented. For now
+/// though, it's fine, the frontend still annotates based on any memtag sanitizer
+/// being used.
+// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=MEMTAG
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule in the ignorelist doesn't change
+/// anything for ASan.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Check that -fsanitize=kernel-address picks up the '[address]' groups.
+// RUN: %clang_cc1 -fsanitize=kernel-address -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// KHWASan doesn't instrument global variables.
+// RUN: %clang_cc1 -fsanitize=kernel-hwaddress -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule doesnt' emit anything for
+/// GVs.
+// RUN: %clang_cc1 -fsanitize=cfi-vcall,cfi-icall -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// NONE: @always_ignored = global
+// NONE-NOT: no_sanitize
+// ASAN: @always_ignored = global {{.*}}, no_sanitize_address
+// HWASAN:   @always_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG:   @always_ignored = global {{.*}}, no_sanitize_memtag
+unsigned always_ignored;
+
+// NONE:   @hwasan_ignored = global
+// NONE-NOT:   no_sanitize
+// ASAN:   @hwasan_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @hwasan_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @hwasan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned hwasan_ignored;
+
+// NONE:   @asan_ignored = global
+// NONE-NOT:   asan_ignored
+// ASAN:   @asan_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @asan_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @asan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned asan_ignored;
+
+// NONE:   @memtag_ignored = global
+// NONE-NOT:   memtag_ignored
+// ASAN:   @memtag_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @memtag_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @memtag_ignored = global {{.*}}, no_sanitize_memtag
+unsigned memtag_ignored;
+
+// NONE:   @never_ignored = global
+// NONE-NOT:   never_ignored
+// ASAN:   @never_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @never_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @never_i

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 436485.
hctim added a comment.

Remove one unnecessary set of brackets before submit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/Inputs/sanitizer-special-case-list-globals.txt
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c

Index: clang/test/CodeGen/sanitizer-special-case-list-globals.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitizer-special-case-list-globals.c
@@ -0,0 +1,91 @@
+/// Verify that ignorelist sections correctly select sanitizers to apply
+/// ignorelist entries to.
+
+// RUN: %clang_cc1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Note: HWASan effectively reorders globals (it puts the unsanitized ones
+/// first), which is hard to check for, as 'CHECK-DAG' doesn't play terribly
+/// nicely with 'CHECK-NOT'. This is why the 'always_ignored' and
+/// 'hwasan_ignored' comes first in this file.
+// RUN: %clang_cc1 -fsanitize=hwaddress -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=HWASAN
+
+/// TODO(hctim): Move over to memtag-globals when it's implemented. For now
+/// though, it's fine, the frontend still annotates based on any memtag sanitizer
+/// being used.
+// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=MEMTAG
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule in the ignorelist doesn't change
+/// anything for ASan.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Check that -fsanitize=kernel-address picks up the '[address]' groups.
+// RUN: %clang_cc1 -fsanitize=kernel-address -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// KHWASan doesn't instrument global variables.
+// RUN: %clang_cc1 -fsanitize=kernel-hwaddress -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule doesnt' emit anything for
+/// GVs.
+// RUN: %clang_cc1 -fsanitize=cfi-vcall,cfi-icall -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// NONE: @always_ignored = global
+// NONE-NOT: no_sanitize
+// ASAN: @always_ignored = global {{.*}}, no_sanitize_address
+// HWASAN:   @always_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG:   @always_ignored = global {{.*}}, no_sanitize_memtag
+unsigned always_ignored;
+
+// NONE:   @hwasan_ignored = global
+// NONE-NOT:   no_sanitize
+// ASAN:   @hwasan_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @hwasan_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @hwasan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned hwasan_ignored;
+
+// NONE:   @asan_ignored = global
+// NONE-NOT:   asan_ignored
+// ASAN:   @asan_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @asan_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @asan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned asan_ignored;
+
+// NONE:   @memtag_ignored = global
+// NONE-NOT:   memtag_ignored
+// ASAN:   @memtag_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @memtag_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @memtag_ignored = global {{.*}}, no_sanitize_memtag
+unsigned memtag_ignored;
+
+// NONE:   @never_ignored = global
+// NONE-NOT:   never_ignored
+// ASAN:   @never_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @never_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @never_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned never_ignored;
Index: clang/test/CodeGen/sanitize-in

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:101
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  llvm::Type::getInt1Ty(VMContext), Meta.IsDynInit)),
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(

vitalybuka wrote:
> Meta.IsDynInit -> IsDynInit
> they must be equal, and this legacy code better not use new Meta.
sure. in practice, `Meta.IsDynInit` is exactly equal to `IsDynInit`, but moved 
it back for now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 436484.
hctim marked 4 inline comments as done.
hctim added a comment.

Final review touch-ups.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/Inputs/sanitizer-special-case-list-globals.txt
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c

Index: clang/test/CodeGen/sanitizer-special-case-list-globals.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitizer-special-case-list-globals.c
@@ -0,0 +1,91 @@
+/// Verify that ignorelist sections correctly select sanitizers to apply
+/// ignorelist entries to.
+
+// RUN: %clang_cc1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Note: HWASan effectively reorders globals (it puts the unsanitized ones
+/// first), which is hard to check for, as 'CHECK-DAG' doesn't play terribly
+/// nicely with 'CHECK-NOT'. This is why the 'always_ignored' and
+/// 'hwasan_ignored' comes first in this file.
+// RUN: %clang_cc1 -fsanitize=hwaddress -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=HWASAN
+
+/// TODO(hctim): Move over to memtag-globals when it's implemented. For now
+/// though, it's fine, the frontend still annotates based on any memtag sanitizer
+/// being used.
+// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=MEMTAG
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule in the ignorelist doesn't change
+/// anything for ASan.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Check that -fsanitize=kernel-address picks up the '[address]' groups.
+// RUN: %clang_cc1 -fsanitize=kernel-address -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// KHWASan doesn't instrument global variables.
+// RUN: %clang_cc1 -fsanitize=kernel-hwaddress -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule doesnt' emit anything for
+/// GVs.
+// RUN: %clang_cc1 -fsanitize=cfi-vcall,cfi-icall -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// NONE: @always_ignored = global
+// NONE-NOT: no_sanitize
+// ASAN: @always_ignored = global {{.*}}, no_sanitize_address
+// HWASAN:   @always_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG:   @always_ignored = global {{.*}}, no_sanitize_memtag
+unsigned always_ignored;
+
+// NONE:   @hwasan_ignored = global
+// NONE-NOT:   no_sanitize
+// ASAN:   @hwasan_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @hwasan_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @hwasan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned hwasan_ignored;
+
+// NONE:   @asan_ignored = global
+// NONE-NOT:   asan_ignored
+// ASAN:   @asan_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @asan_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @asan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned asan_ignored;
+
+// NONE:   @memtag_ignored = global
+// NONE-NOT:   memtag_ignored
+// ASAN:   @memtag_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @memtag_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @memtag_ignored = global {{.*}}, no_sanitize_memtag
+unsigned memtag_ignored;
+
+// NONE:   @never_ignored = global
+// NONE-NOT:   never_ignored
+// ASAN:   @never_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @never_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @never_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned never_ignored;
Index: clang/test/CodeGen/s

[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Looks like this broke the ASan buildbot (and may have been missed because the 
bot was already red at the time):

https://lab.llvm.org/buildbot/#/builders/5/builds/24588

Instructions on how to repro the bot are here: 
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

  FAIL: Clang :: Interpreter/execute.cpp (9159 of 66378)
   TEST 'Clang :: Interpreter/execute.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang-repl "int i = 
10;" 'extern "C" int printf(const char*,...);' 'auto r1 = printf("i 
= %d\n", i);' | 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck 
--check-prefix=CHECK-DRIVER 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/execute.cpp
  : 'RUN: at line 6';   cat 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/execute.cpp
 | /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang-repl | 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/execute.cpp
  --
  Exit Code: 2
  Command Output (stderr):
  --
  =
  ==58455==ERROR: LeakSanitizer: detected memory leaks
  Direct leak of 3912 byte(s) in 3 object(s) allocated from:
  #0 0x55f45fa2983d in operator new(unsigned long) 
/b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
  #1 0x55f4600f75ad in 
llvm::RegisterTargetMachine::Allocator(llvm::Target 
const&, llvm::Triple const&, llvm::StringRef, llvm::StringRef, 
llvm::TargetOptions const&, llvm::Optional, 
llvm::Optional, llvm::CodeGenOpt::Level, bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/MC/TargetRegistry.h:1306:12
  #2 0x55f46267c8bb in createTargetMachine 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/MC/TargetRegistry.h:466:12
  #3 0x55f46267c8bb in CreateTargetMachine 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:560:23
  #4 0x55f46267c8bb in EmitAssembly 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1012:3
  #5 0x55f46267c8bb in clang::EmitBackendOutput(clang::DiagnosticsEngine&, 
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, 
clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, 
llvm::Module*, clang::BackendAction, 
std::__1::unique_ptr>) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1182:13
  #6 0x55f4626736e5 in 
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:379:7
  #7 0x55f4615be6cc in clang::IncrementalParser::ParseOrWrapTopLevelDecl() 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Interpreter/IncrementalParser.cpp:218:13
  #8 0x55f4615c0e13 in clang::IncrementalParser::Parse(llvm::StringRef) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Interpreter/IncrementalParser.cpp:265:14
  #9 0x55f4615bb814 in clang::Interpreter::Parse(llvm::StringRef) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Interpreter/Interpreter.cpp:207:22
  #10 0x55f45fa30581 in 
clang::Interpreter::ParseAndExecute(llvm::StringRef) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/include/clang/Interpreter/Interpreter.h:64:16
  #11 0x55f45fa2e95c in main 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/clang-repl/ClangRepl.cpp:97:30
  #12 0x7fde05cc509a in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2409a) (BuildId: 
eb6a5dd378d22b1e695984462a799cd4c81cdc22)
  
  Indirect leak of 32776 byte(s) in 1 object(s) allocated from:
  #0 0x55f45f9f8c88 in calloc 
/b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:77:3
  #1 0x55f460cf72a2 in safe_calloc 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/Support/MemAlloc.h:40:18
  #2 0x55f460cf72a2 in AllocateBuckets 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/FoldingSet.cpp:173:40
  #3 0x55f460cf72a2 in llvm::FoldingSetBase::FoldingSetBase(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/FoldingSet.cpp:187:13
  #4 0x55f46a156d6a in FoldingSetImpl 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FoldingSet.h:438:9
  #5 0x55f46a156d6a in ContextualFoldingSet 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FoldingSet.h:620:9
  #6 0x55f46a156d6a in clang::ASTContext::ASTContext(clang::LangOptions&, 
clang::SourceManager&, clang::IdentifierTable&, clang::SelectorTable&, 
clang::Builtin::Context&, clang::TranslationUnitKind) 
/b/sanitizer-x86_6

[PATCH] D119367: [HWASan] Allow no_sanitize(..) and change metadata passing.

2022-06-10 Thread Mitch Phillips via Phabricator via cfe-commits
hctim abandoned this revision.
hctim added a comment.
Herald added a subscriber: Enna1.
Herald added a project: All.

Deprecated by D127544 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119367/new/

https://reviews.llvm.org/D119367

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127163: [clang] Add -fsanitize=memtag-globals (no-op).

2022-06-10 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 436059.
hctim marked 2 inline comments as done.
hctim added a comment.

update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127163/new/

https://reviews.llvm.org/D127163

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -193,9 +193,9 @@
 // RUN: %clang -target x86_64-linux-android -fsanitize=memtag -fno-rtti %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-BAD-ARCH
 // CHECK-SANMT-BAD-ARCH: unsupported option '-fsanitize=memtag' for target
 
-// RUN: %clang -target aarch64-linux -fsanitize=memtag -march=armv8-a+memtag 
%s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-MT
+// RUN: %clang -target aarch64-linux-android31 -fsanitize=memtag 
-march=armv8-a+memtag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-MT
 // CHECK-SANMT-MT: "-target-feature" "+mte"
-// CHECK-SANMT-MT-SAME: "-fsanitize=memtag-stack,memtag-heap"
+// CHECK-SANMT-MT-SAME: "-fsanitize=memtag-stack,memtag-heap,memtag-globals"
 
 // RUN: %clang -target aarch64-linux -fsanitize=memtag %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-SANMT-NOMT-0
 // CHECK-SANMT-NOMT-0: '-fsanitize=memtag-stack' requires hardware support 
(+memtag)
@@ -827,7 +827,7 @@
 // CHECK-INTSAN-MINIMAL: "-fsanitize-minimal-runtime"
 
 // RUN: %clang -target aarch64-linux-android -march=armv8-a+memtag 
-fsanitize=memtag -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MEMTAG-MINIMAL
-// CHECK-MEMTAG-MINIMAL: "-fsanitize=memtag-stack,memtag-heap"
+// CHECK-MEMTAG-MINIMAL: "-fsanitize=memtag-stack,memtag-heap,memtag-globals"
 // CHECK-MEMTAG-MINIMAL: "-fsanitize-minimal-runtime"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
-fsanitize=function -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-UBSAN-FUNCTION-MINIMAL
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -45,7 +45,8 @@
 SanitizerKind::Address | SanitizerKind::HWAddress |
 SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress |
 SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap |
-SanitizerKind::Memory | SanitizerKind::KernelMemory | SanitizerKind::Leak |
+SanitizerKind::MemtagGlobals | SanitizerKind::Memory |
+SanitizerKind::KernelMemory | SanitizerKind::Leak |
 SanitizerKind::Undefined | SanitizerKind::Integer | SanitizerKind::Bounds |
 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
 SanitizerKind::DataFlow | SanitizerKind::Fuzzer |
@@ -73,7 +74,8 @@
 SanitizerKind::CFIUnrelatedCast;
 static const SanitizerMask CompatibleWithMinimalRuntime =
 TrappingSupported | SanitizerKind::Scudo | SanitizerKind::ShadowCallStack |
-SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap;
+SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap |
+SanitizerKind::MemtagGlobals;
 
 enum CoverageFeature {
   CoverageFunc = 1 << 0,
Index: clang/include/clang/Driver/SanitizerArgs.h
===
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -99,13 +99,18 @@
   bool needsStatsRt() const { return Stats; }
   bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
 
-  bool hasMemTag() const { return hasMemtagHeap() || hasMemtagStack(); }
+  bool hasMemTag() const {
+return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
+  }
   bool hasMemtagHeap() const {
 return Sanitizers.has(SanitizerKind::MemtagHeap);
   }
   bool hasMemtagStack() const {
 return Sanitizers.has(SanitizerKind::MemtagStack);
   }
+  bool hasMemtagGlobals() const {
+return Sanitizers.has(SanitizerKind::MemtagGlobals);
+  }
   const std::string &getMemtagMode() const {
 assert(!MemtagMode.empty());
 return MemtagMode;
Index: clang/include/clang/Basic/Sanitizers.def
===
--- clang/include/clang/Basic/Sanitizers.def
+++ clang/include/clang/Basic/Sanitizers.def
@@ -58,7 +58,8 @@
 // A variant of AddressSanitizer using AArch64 MTE extension.
 SANITIZER("memtag-stack", MemtagStack)
 SANITIZER("memtag-heap", MemtagHeap)
-SANITIZER_GROUP("memtag", MemTag, MemtagStack | MemtagHeap)
+SANITIZER("memtag-globals", MemtagGlobals)
+SANITIZER_GROUP("memtag", MemTag, MemtagStack | MemtagHeap | MemtagGlobals)
 
 // MemorySanitizer
 SANITIZER("memory", Memory)
Index: clang/include/clang/Basic/Features.def

[PATCH] D127163: [clang] Add -fsanitize=memtag-globals (no-op).

2022-06-10 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 2 inline comments as done.
hctim added inline comments.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:767
+  if (IsAArch64) {
+Res |= SanitizerKind::MemtagGlobals;
+  }

eugenis wrote:
> Hmm why are all the other memtag* not here?
Yeah, just realised this isn't necessary, looks like it's covered in 
`clang/lib/Driver/ToolChain.cpp:1088` (the entire bitset of `MemTag`, which is 
`MemtagStack | MemtagGlobals | MemtagHeap`).



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7892
 
+static bool isSanitizerThatUsesGlobals(StringRef Sanitizer) {
+  return Sanitizer == "address" || Sanitizer == "hwaddress" ||

eugenis wrote:
> Maybe "applies to globals"? On the other hand, MSan "applies" to globals but 
> does not need this logic.
> 
> isSanitizerAttributeAllowedOnGlobals?
yeah, `isSanitizerAttributeAllowedOnGlobals` sounds good to me. also pulled 
this over to a different change adding support for 
`__attribute__((no_sanitize("hwaddress")))`: D127544


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127163/new/

https://reviews.llvm.org/D127163

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-10 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: pcc.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: Enna1.
Herald added a project: All.
hctim requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Currently, __attribute__((no_sanitize('hwaddress'))) is not possible. Add this 
piece of plumbing, and now that we properly support copying attributes between 
an old and a new global variable, add a regression test for the GlobalOpt bug 
that previously lost the attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127544

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  compiler-rt/test/hwasan/TestCases/global-with-reduction.c
  compiler-rt/test/hwasan/TestCases/global.c

Index: compiler-rt/test/hwasan/TestCases/global.c
===
--- compiler-rt/test/hwasan/TestCases/global.c
+++ compiler-rt/test/hwasan/TestCases/global.c
@@ -14,9 +14,23 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
+#include 
+
+int a = 1;
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) int x = 1;
+#else // USE_NOSANITIZE
 int x = 1;
+#endif // USE_NOSANITIZE
+int b = 1;
 
 int atoi(const char *);
 
@@ -30,4 +44,5 @@
   // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
   // CHECK-NOT: can not describe
   (&x)[atoi(argv[1])] = 1;
+  return 0;
 }
Index: compiler-rt/test/hwasan/TestCases/global-with-reduction.c
===
--- compiler-rt/test/hwasan/TestCases/global-with-reduction.c
+++ compiler-rt/test/hwasan/TestCases/global-with-reduction.c
@@ -14,20 +14,38 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
-int x = 1;
+#include 
 
-int atoi(const char *);
+// GlobalOpt may replace the current GV with a new boolean-typed GV. Previously,
+// this resulted in the "nosanitize" getting dropped because while the data/code
+// references to the GV were updated, the old metadata references weren't.
+int* f() {
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) static int x = 1;
+#else // USE_NOSANITIZE
+  static int x = 1;
+#endif // USE_NOSANITIZE
+  if (x == 1) x = 0;
+  return &x;
+}
 
 int main(int argc, char **argv) {
   // CHECK: Cause: global-overflow
-  // RSYM: is located 0 bytes to the right of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RSYM: is located 0 bytes to the right of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // RNOSYM: is located to the right of a 4-byte global variable in
-  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
-  // LSYM: is located 4 bytes to the left of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
+  // LSYM: is located 4 bytes to the left of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // LNOSYM: is located to the left of a 4-byte global variable in
-  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
+  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
   // CHECK-NOT: can not describe
-  (&x)[atoi(argv[1])] = 1;
+  f()[atoi(argv[1])] = 1;
+  return 0;
 }
Index: clang/test/CodeGen/hwasan-globals.cpp
===
--- /dev/null
+++ clang/test/CodeGen/hwasan-globals.cpp
@@ -0,0 +1,55 @@
+// RUN: echo "int extra_global;" > %t.extra-source.cpp
+// RUN: echo "global:*ignorelisted_global*" > %t.ignorelist
+// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=hwaddress -fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK
+// The ignorelist file uses regexps, so Windows path backslashes.
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t.ignorelist-src
+// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=hwaddress -fsanitize-ignorelist=%t.ignorelist-src -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST
+
+int global;
+int __attribute__((no_sanitize("hwaddres

[PATCH] D126100: Add sanitizer-specific GlobalValue attributes.

2022-06-10 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hctim marked an inline comment as done.
Closed by commit rG8db981d463ee: Add sanitizer-specific GlobalValue attributes. 
(authored by hctim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126100/new/

https://reviews.llvm.org/D126100

Files:
  llvm/include/llvm/AsmParser/LLParser.h
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Assembler/globalvariable-attributes.ll
  llvm/test/Bitcode/compatibility.ll

Index: llvm/test/Bitcode/compatibility.ll
===
--- llvm/test/Bitcode/compatibility.ll
+++ llvm/test/Bitcode/compatibility.ll
@@ -203,6 +203,18 @@
 @llvm.global_dtors = appending global [1 x %pri.func.data] [%pri.func.data { i32 0, void ()* @g.f1, i8* @g.used3 }], section "llvm.metadata"
 ; CHECK: @llvm.global_dtors = appending global [1 x %pri.func.data] [%pri.func.data { i32 0, void ()* @g.f1, i8* @g.used3 }], section "llvm.metadata"
 
+; Global Variables -- sanitizers
+@g.no_sanitize_address = global i32 0, no_sanitize_address
+@g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
+@g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
+@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+@g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+; CHECK: @g.no_sanitize_address = global i32 0, no_sanitize_address
+; CHECK: @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
+; CHECK: @g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
+; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+; CHECK: @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+
 ;; Aliases
 ; Format: @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
 ;   [unnamed_addr] alias  @
Index: llvm/test/Assembler/globalvariable-attributes.ll
===
--- llvm/test/Assembler/globalvariable-attributes.ll
+++ llvm/test/Assembler/globalvariable-attributes.ll
@@ -4,6 +4,11 @@
 @g2 = global i32 2, align 4 "key3" = "value3"
 @g3 = global i32 2 #0
 @g4 = global i32 2, align 4 "key5" = "value5" #0
+@g5 = global i32 2, no_sanitize_address, align 4
+@g6 = global i32 2, no_sanitize_hwaddress, align 4
+@g7 = global i32 2, no_sanitize_memtag, align 4
+@g8 = global i32 2, sanitize_address_dyninit, align 4
+@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
 
 attributes #0 = { "string" = "value" nobuiltin norecurse }
 
@@ -11,6 +16,11 @@
 ; CHECK: @g2 = global i32 2, align 4 #1
 ; CHECK: @g3 = global i32 2 #2
 ; CHECK: @g4 = global i32 2, align 4 #3
+; CHECK: @g5 = global i32 2, no_sanitize_address, align 4
+; CHECK: @g6 = global i32 2, no_sanitize_hwaddress, align 4
+; CHECK: @g7 = global i32 2, no_sanitize_memtag, align 4
+; CHECK: @g8 = global i32 2, sanitize_address_dyninit, align 4
+; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
 
 ; CHECK: attributes #0 = { "key"="value" "key2"="value2" }
 ; CHECK: attributes #1 = { "key3"="value3" }
Index: llvm/lib/IR/LLVMContextImpl.h
===
--- llvm/lib/IR/LLVMContextImpl.h
+++ llvm/lib/IR/LLVMContextImpl.h
@@ -1503,6 +1503,9 @@
   /// Collection of per-GlobalValue partitions used in this context.
   DenseMap GlobalValuePartitions;
 
+  DenseMap
+  GlobalValueSanitizerMetadata;
+
   /// DiscriminatorTable - This table maps file:line locations to an
   /// integer representing the next DWARF path discriminator to assign to
   /// instructions in different blocks at the same location.
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -67,6 +67,10 @@
   setDLLStorageClass(Src->getDLLStorageClass());
   setDSOLocal(Src->isDSOLocal());
   setPartition(Src->getPartition());
+  if (Src->hasSanitizerMetadata())
+setSanitizerMetadata(Src->getSanitizerMetadata());
+  else
+removeSanitizerMetadata();
 }
 
 void GlobalValue::removeFromParent() {
@@ -217,6 +221,27 @@
   HasPartition = !S.empty();
 }
 
+using SanitizerMetadata = GlobalValue::SanitizerMetadata;
+const SanitizerMetadata &GlobalValue::getSanitizerMetadata() const {
+  assert(hasSanitizerMetadata());
+  assert(getContext().pImpl->GlobalValueSanitizerMetadata.count(this));
+  return getContext().pImpl->GlobalValueSanitizerMetadata[this];

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-09 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 435671.
hctim added a comment.

And some small diff-reducing touch ups


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/Inputs/sanitizer-special-case-list-globals.txt
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c

Index: clang/test/CodeGen/sanitizer-special-case-list-globals.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitizer-special-case-list-globals.c
@@ -0,0 +1,91 @@
+/// Verify that ignorelist sections correctly select sanitizers to apply
+/// ignorelist entries to.
+
+// RUN: %clang_cc1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Note: HWASan effectively reorders globals (it puts the unsanitized ones
+/// first), which is hard to check for, as 'CHECK-DAG' doesn't play terribly
+/// nicely with 'CHECK-NOT'. This is why the 'always_ignored' and
+/// 'hwasan_ignored' comes first in this file.
+// RUN: %clang_cc1 -fsanitize=hwaddress -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=HWASAN
+
+/// TODO(hctim): Move over to memtag-globals when it's implemented. For now
+/// though, it's fine, the frontend still annotates based on any memtag sanitizer
+/// being used.
+// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=MEMTAG
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule in the ignorelist doesn't change
+/// anything for ASan.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Check that -fsanitize=kernel-address picks up the '[address]' groups.
+// RUN: %clang_cc1 -fsanitize=kernel-address -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// KHWASan doesn't instrument global variables.
+// RUN: %clang_cc1 -fsanitize=kernel-hwaddress -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule doesnt' emit anything for
+/// GVs.
+// RUN: %clang_cc1 -fsanitize=cfi-vcall,cfi-icall -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// NONE: @always_ignored = global
+// NONE-NOT: no_sanitize
+// ASAN: @always_ignored = global {{.*}}, no_sanitize_address
+// HWASAN:   @always_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG:   @always_ignored = global {{.*}}, no_sanitize_memtag
+unsigned always_ignored;
+
+// NONE:   @hwasan_ignored = global
+// NONE-NOT:   no_sanitize
+// ASAN:   @hwasan_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @hwasan_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @hwasan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned hwasan_ignored;
+
+// NONE:   @asan_ignored = global
+// NONE-NOT:   asan_ignored
+// ASAN:   @asan_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @asan_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @asan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned asan_ignored;
+
+// NONE:   @memtag_ignored = global
+// NONE-NOT:   memtag_ignored
+// ASAN:   @memtag_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @memtag_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @memtag_ignored = global {{.*}}, no_sanitize_memtag
+unsigned memtag_ignored;
+
+// NONE:   @never_ignored = global
+// NONE-NOT:   never_ignored
+// ASAN:   @never_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @never_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @never_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned never_ignored;
Index: clang/test/CodeGen/sanitize-init-order.cpp
==

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-09 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 435669.
hctim added a comment.

Remove two unnecessary braces.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/Inputs/sanitizer-special-case-list-globals.txt
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c

Index: clang/test/CodeGen/sanitizer-special-case-list-globals.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitizer-special-case-list-globals.c
@@ -0,0 +1,91 @@
+/// Verify that ignorelist sections correctly select sanitizers to apply
+/// ignorelist entries to.
+
+// RUN: %clang_cc1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Note: HWASan effectively reorders globals (it puts the unsanitized ones
+/// first), which is hard to check for, as 'CHECK-DAG' doesn't play terribly
+/// nicely with 'CHECK-NOT'. This is why the 'always_ignored' and
+/// 'hwasan_ignored' comes first in this file.
+// RUN: %clang_cc1 -fsanitize=hwaddress -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=HWASAN
+
+/// TODO(hctim): Move over to memtag-globals when it's implemented. For now
+/// though, it's fine, the frontend still annotates based on any memtag sanitizer
+/// being used.
+// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=MEMTAG
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule in the ignorelist doesn't change
+/// anything for ASan.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Check that -fsanitize=kernel-address picks up the '[address]' groups.
+// RUN: %clang_cc1 -fsanitize=kernel-address -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// KHWASan doesn't instrument global variables.
+// RUN: %clang_cc1 -fsanitize=kernel-hwaddress -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule doesnt' emit anything for
+/// GVs.
+// RUN: %clang_cc1 -fsanitize=cfi-vcall,cfi-icall -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// NONE: @always_ignored = global
+// NONE-NOT: no_sanitize
+// ASAN: @always_ignored = global {{.*}}, no_sanitize_address
+// HWASAN:   @always_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG:   @always_ignored = global {{.*}}, no_sanitize_memtag
+unsigned always_ignored;
+
+// NONE:   @hwasan_ignored = global
+// NONE-NOT:   no_sanitize
+// ASAN:   @hwasan_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @hwasan_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @hwasan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned hwasan_ignored;
+
+// NONE:   @asan_ignored = global
+// NONE-NOT:   asan_ignored
+// ASAN:   @asan_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @asan_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @asan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned asan_ignored;
+
+// NONE:   @memtag_ignored = global
+// NONE-NOT:   memtag_ignored
+// ASAN:   @memtag_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @memtag_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @memtag_ignored = global {{.*}}, no_sanitize_memtag
+unsigned memtag_ignored;
+
+// NONE:   @never_ignored = global
+// NONE-NOT:   never_ignored
+// ASAN:   @never_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @never_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @never_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned never_ignored;
Index: clang/test/CodeGen/sanitize-init-order.cpp
==

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-09 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 435667.
hctim marked 3 inline comments as done.
hctim added a comment.

update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/Inputs/sanitizer-special-case-list-globals.txt
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c

Index: clang/test/CodeGen/sanitizer-special-case-list-globals.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitizer-special-case-list-globals.c
@@ -0,0 +1,91 @@
+/// Verify that ignorelist sections correctly select sanitizers to apply
+/// ignorelist entries to.
+
+// RUN: %clang_cc1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Note: HWASan effectively reorders globals (it puts the unsanitized ones
+/// first), which is hard to check for, as 'CHECK-DAG' doesn't play terribly
+/// nicely with 'CHECK-NOT'. This is why the 'always_ignored' and
+/// 'hwasan_ignored' comes first in this file.
+// RUN: %clang_cc1 -fsanitize=hwaddress -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=HWASAN
+
+/// TODO(hctim): Move over to memtag-globals when it's implemented. For now
+/// though, it's fine, the frontend still annotates based on any memtag sanitizer
+/// being used.
+// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=MEMTAG
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule in the ignorelist doesn't change
+/// anything for ASan.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// Check that -fsanitize=kernel-address picks up the '[address]' groups.
+// RUN: %clang_cc1 -fsanitize=kernel-address -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+/// KHWASan doesn't instrument global variables.
+// RUN: %clang_cc1 -fsanitize=kernel-hwaddress -mllvm -hwasan-kernel=1 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+/// Check that the '[cfi-vcall|cfi-icall] src:*' rule doesnt' emit anything for
+/// GVs.
+// RUN: %clang_cc1 -fsanitize=cfi-vcall,cfi-icall -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=NONE
+
+// NONE: @always_ignored = global
+// NONE-NOT: no_sanitize
+// ASAN: @always_ignored = global {{.*}}, no_sanitize_address
+// HWASAN:   @always_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG:   @always_ignored = global {{.*}}, no_sanitize_memtag
+unsigned always_ignored;
+
+// NONE:   @hwasan_ignored = global
+// NONE-NOT:   no_sanitize
+// ASAN:   @hwasan_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @hwasan_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @hwasan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned hwasan_ignored;
+
+// NONE:   @asan_ignored = global
+// NONE-NOT:   asan_ignored
+// ASAN:   @asan_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @asan_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @asan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned asan_ignored;
+
+// NONE:   @memtag_ignored = global
+// NONE-NOT:   memtag_ignored
+// ASAN:   @memtag_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @memtag_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @memtag_ignored = global {{.*}}, no_sanitize_memtag
+unsigned memtag_ignored;
+
+// NONE:   @never_ignored = global
+// NONE-NOT:   never_ignored
+// ASAN:   @never_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @never_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @never_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned never_ignored;
Index: clang/test/CodeGen/sanitize-init-orde

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-09 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 10 inline comments as done.
hctim added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2767-2781
+  if (NoSanitizeL.containsGlobal(LangOpts.Sanitize.Mask, GV->getName(), 
Category))
 return true;
-  if (NoSanitizeL.containsLocation(EnabledAsanMask, Loc, Category))
+  if (NoSanitizeL.containsLocation(LangOpts.Sanitize.Mask, Loc, Category))
 return true;
   // Check global type.
   if (!Ty.isNull()) {
 // Drill down the array types: if global variable of a fixed type is

hctim wrote:
> vitalybuka wrote:
> > can this lines be landed separately?
> sure
(now we do touch a little bit here regardless)



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:55
+
+  bool IsExcluded = CGM.isInNoSanitizeList(GV, Loc, Ty);
+  IsExcluded |= (NoSanitizeMask == SanitizerKind::All);

vitalybuka wrote:
> vitalybuka wrote:
> > it can be in some weird ubsan check ignore list, and this way it will 
> > propagate on asan/hwasan
> > I don't think you can avoid extending isInNoSanitizeList (in a separate 
> > patch)
> you you can introduce:
> 
> ```
> bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, 
> llvm::GlobalVariable *GV,
>SourceLocation Loc) const {
> ```
> 
> similar to
> 
> ```
> bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
>SourceLocation Loc) const {
> ```
done, but bearing in mind if you have some global `src:` exclude in an 
`-fsanitize-ignorelist` that's designed to ignore some file for UBSan, and then 
you compile with `-fsanitize=address,undefined` and use that 
`-fsanitize-ignorelist`, then those GVs would also be ignored in ASan. The 
right way to go about that is to have the creator of the ignorelist make sure 
that the `src:` rule is in a `[undefined]` block. Added the expected use case 
to `sanitizer-special-case-list-globals.txt`.

i think it's small enough a change + relevant enough to this CL to not fork it 
out to a different patch and then have to do the cleanup twice.



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:64
  bool IsDynInit) {
-  if (!isAsanHwasanOrMemTag(CGM.getLangOpts().Sanitize))
-return;

vitalybuka wrote:
> May be early isAsanHwasanOrMemTag check here is useful to avoid string stuff 
> below for compilation without sanitizers.
sure, also hoisted the other check up



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:70
 
-  auto getNoSanitizeMask = [](const VarDecl &D) {
-if (D.hasAttr())

vitalybuka wrote:
> I don't insist but one it's cleaner with lambda and return
> if you prefer your way please revert lambda in a separate patch
reverted it back, lambda here seems very fancy for a simple farmer like me, but 
i can't deny that it's pretty.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-08 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 435257.
hctim marked 3 inline comments as done.
hctim added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/Inputs/sanitizer-special-case-list-globals.txt
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c

Index: clang/test/CodeGen/sanitizer-special-case-list-globals.c
===
--- /dev/null
+++ clang/test/CodeGen/sanitizer-special-case-list-globals.c
@@ -0,0 +1,55 @@
+// Verify that ignorelist sections correctly select sanitizers to apply
+// ignorelist entries to.
+
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=ASAN
+
+// Note: HWASan effectively reorders globals (it puts the unsanitized ones
+// first), which is hard to check for, as 'CHECK-DAG' doesn't play terribly
+// nicely with 'CHECK-NOT'. This is why the 'always_ignored' and
+// 'hwasan_ignored' comes first in this file.
+// RUN: %clang_cc1 -fsanitize=hwaddress -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=HWASAN
+
+// TODO(hctim): Move over to memtag-globals when it's implemented. For now
+// though, it's fine, the frontend still annotates based on any memtag sanitizer
+// being used.
+// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\
+// RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \
+// RUN: | FileCheck %s --check-prefix=MEMTAG
+
+// ASAN:   @always_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @always_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @always_ignored = global {{.*}}, no_sanitize_memtag
+unsigned always_ignored;
+
+// ASAN:   @hwasan_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @hwasan_ignored = global {{.*}}, no_sanitize_hwaddress
+// MEMTAG: @hwasan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned hwasan_ignored;
+
+// ASAN:   @asan_ignored = global {{.*}}, no_sanitize_address
+// HWASAN: @asan_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @asan_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned asan_ignored;
+
+// ASAN:   @memtag_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @memtag_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @memtag_ignored = global {{.*}}, no_sanitize_memtag
+unsigned memtag_ignored;
+
+// ASAN:   @never_ignored = global
+// ASAN-NOT:   no_sanitize_address
+// HWASAN: @never_ignored.hwasan = {{.*}} global
+// HWASAN-NOT: no_sanitize_hwaddress
+// MEMTAG: @never_ignored = global
+// MEMTAG-NOT: no_sanitize_memtag
+unsigned never_ignored;
Index: clang/test/CodeGen/sanitize-init-order.cpp
===
--- clang/test/CodeGen/sanitize-init-order.cpp
+++ clang/test/CodeGen/sanitize-init-order.cpp
@@ -36,12 +36,29 @@
 
 // Check that ASan init-order checking ignores structs with trivial default
 // constructor.
+
+// CHECK: @s1 = global
+// CHECK-NOT: sanitize_address_dyninit
+// CHECK: @s2 = global
+// CHECK-NOT: sanitize_address_dyninit
+// CHECK: @s3 = global {{.*}}, sanitize_address_dyninit
+// CHECK: @{{.*}}array{{.*}} = global {{.*}}, sanitize_address_dyninit
+
 // CHECK: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], ![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]
 // CHECK: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
 // CHECK: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
 // CHECK: ![[GLOB_3]] = !{%struct.PODWithCtorAndDtor* {{.*}}, i1 true, i1 false}
 // CHECK: ![[GLOB_4]] = !{{{.*}}class.NS::PODWithCtor{{.*}}, i1 true, i1 false}
 
+// IGNORELIST: @s1 = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+// IGNORELIST: @s2 = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+// IGNORELIST: @s3 = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+// IGNORELIST: @{{.*}}array{{.*}} = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+
 // IGNORELIST: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], ![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]}
 // IGNORELIST: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
 // IGNORELIST: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@

[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-08 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 3 inline comments as done.
hctim added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2767-2781
+  if (NoSanitizeL.containsGlobal(LangOpts.Sanitize.Mask, GV->getName(), 
Category))
 return true;
-  if (NoSanitizeL.containsLocation(EnabledAsanMask, Loc, Category))
+  if (NoSanitizeL.containsLocation(LangOpts.Sanitize.Mask, Loc, Category))
 return true;
   // Check global type.
   if (!Ty.isNull()) {
 // Drill down the array types: if global variable of a fixed type is

vitalybuka wrote:
> can this lines be landed separately?
sure



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:44
 
+  if (CGM.isInNoSanitizeList(GV, Loc, Ty))
+Meta.NoSanitize = true;

vitalybuka wrote:
> it's incorrect as is
> isInNoSanitizeList is sanitizer specific
> we need to add isInNoSanitizeList version which return relevant SanitizerMask
sure, added the sanitizer-specific parsing as well, including a test 
(sanitizer-special-case-list-globals.txt)



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:69
+  SanitizerKind::KernelAddress)) {
+Meta.IsDynInit = IsDynInit && !CGM.isInNoSanitizeList(GV, Loc, Ty, "init");
+  }

vitalybuka wrote:
> Why don't we care about IsExcluded here?
doesn't matter as the global is disabled anyway, and this preserves previous 
behaviour which the existing tests assert on.

i'll make it conditional in the follow up change, as all the 
`llvm.asan.globals` tests need to be deleted. added a note.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126929/new/

https://reviews.llvm.org/D126929

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >