Skip to content

Commit

Permalink
Revert "Reapply "[HWASan] remove incorrectly inferred attributes" (#1…
Browse files Browse the repository at this point in the history
…06622)" (#106758)

Reverts #106624

caused timeouts
  • Loading branch information
fmayer authored Aug 30, 2024
1 parent f1cf091 commit f81f283
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 451 deletions.
28 changes: 14 additions & 14 deletions clang/test/CodeGen/address-safety-attr-flavors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,57 @@ int HasSanitizeAddress() { return 1; }
// CHECK-NOASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-ASAN: Function Attrs: mustprogress noinline nounwind sanitize_address
// CHECK-KASAN: Function Attrs: mustprogress noinline nounwind sanitize_address
// CHECK-HWASAN: Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress
// CHECK-KHWASAN: Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress
// CHECK-HWASAN: Function Attrs: mustprogress noinline nounwind sanitize_hwaddress
// CHECK-KHWASAN: Function Attrs: mustprogress noinline nounwind sanitize_hwaddress

__attribute__((no_sanitize("address"))) int NoSanitizeQuoteAddress() {
return 0;
}
// CHECK-NOASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-ASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-KASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_hwaddress$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_hwaddress$}}

__attribute__((no_sanitize_address)) int NoSanitizeAddress() { return 0; }
// CHECK-NOASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-ASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-KASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_hwaddress$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_hwaddress$}}

__attribute__((no_sanitize("kernel-address"))) int NoSanitizeKernelAddress() {
return 0;
}
// CHECK-NOASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-ASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-KASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind sanitize_hwaddress$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_hwaddress$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_hwaddress$}}

__attribute__((no_sanitize("hwaddress"))) int NoSanitizeHWAddress() {
return 0;
}
// CHECK-NOASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-ASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_address$}}
// CHECK-KASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_address$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress noinline nounwind$}}

__attribute__((no_sanitize("kernel-hwaddress"))) int NoSanitizeKernelHWAddress() {
return 0;
}
// CHECK-NOASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-ASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_address$}}
// CHECK-KASAN: {{Function Attrs: mustprogress noinline nounwind sanitize_address$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress nobuiltin noinline nounwind$}}
// CHECK-HWASAN: {{Function Attrs: mustprogress noinline nounwind$}}
// CHECK-KHWASAN: {{Function Attrs: mustprogress noinline nounwind$}}

__attribute__((disable_sanitizer_instrumentation)) int DisableSanitizerInstrumentation() {
return 0;
}
// CHECK-NOASAN: {{Function Attrs: disable_sanitizer_instrumentation mustprogress noinline nounwind$}}
// CHECK-ASAN: {{Function Attrs: disable_sanitizer_instrumentation mustprogress noinline nounwind$}}
// CHECK-KASAN: {{Function Attrs: disable_sanitizer_instrumentation mustprogress noinline nounwind$}}
// CHECK-HWASAN: {{Function Attrs: disable_sanitizer_instrumentation mustprogress nobuiltin noinline nounwind$}}
// CHECK-KHWASAN: {{Function Attrs: disable_sanitizer_instrumentation mustprogress nobuiltin noinline nounwind$}}
// CHECK-HWASAN: {{Function Attrs: disable_sanitizer_instrumentation mustprogress noinline nounwind$}}
// CHECK-KHWASAN: {{Function Attrs: disable_sanitizer_instrumentation mustprogress noinline nounwind$}}
26 changes: 8 additions & 18 deletions llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,24 +598,6 @@ void HWAddressSanitizer::initializeModule() {
LLVM_DEBUG(dbgs() << "Init " << M.getName() << "\n");
TargetTriple = Triple(M.getTargetTriple());

for (auto &F : M.functions()) {
// Remove memory attributes that are invalid with HWASan.
// HWASan checks read from shadow, which invalidates memory(argmem: *)
// Short granule checks on function arguments read from the argument memory
// (last byte of the granule), which invalidates writeonly.
//
// This is not only true for sanitized functions, because AttrInfer can
// infer those attributes on libc functions, which is not true if those
// are instrumented (Android) or intercepted.

// nobuiltin makes sure later passes don't restore assumptions about
// the function.
F.addFnAttr(llvm::Attribute::NoBuiltin);
F.removeFnAttr(llvm::Attribute::Memory);
for (auto &A : F.args())
A.removeAttr(llvm::Attribute::WriteOnly);
}

// x86_64 currently has two modes:
// - Intel LAM (default)
// - pointer aliasing (heap only)
Expand Down Expand Up @@ -1640,6 +1622,14 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,

assert(!ShadowBase);

// Remove memory attributes that are about to become invalid.
// HWASan checks read from shadow, which invalidates memory(argmem: *)
// Short granule checks on function arguments read from the argument memory
// (last byte of the granule), which invalidates writeonly.
F.removeFnAttr(llvm::Attribute::Memory);
for (auto &A : F.args())
A.removeAttr(llvm::Attribute::WriteOnly);

BasicBlock::iterator InsertPt = F.getEntryBlock().begin();
IRBuilder<> EntryIRB(&F.getEntryBlock(), InsertPt);
emitPrologue(EntryIRB,
Expand Down
Loading

0 comments on commit f81f283

Please sign in to comment.