[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

> Looks like the same issue I fixed in https://reviews.llvm.org/rGd97bab651185. 
>  Let me know if you have the issue after that commit.

Thanks, that resolved the build issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

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


[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

In D102286#2764203 , @gulfem wrote:

> We started seeing test failures in our Windows builds in Fuchsia after this 
> patch.
>
>   FAILED: 
> compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
>  
>   C:\b\s\w\ir\x\w\staging\llvm_build\.\bin\clang++.exe 
> --target=aarch64-unknown-linux-gnu --sysroot=C:/b/s/w/ir/x/w/cipd/linux  
> -DHWASAN_WITH_INTERCEPTORS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS 
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
> -IC:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/.. 
> --target=aarch64-unknown-linux-gnu -fPIC -fvisibility-inlines-hidden 
> -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
> -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default 
> -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
> -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation 
> -fdiagnostics-color -ffunction-sections -fdata-sections 
> -ffile-prefix-map=C:/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins=../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins
>  -ffile-prefix-map=C:/b/s/w/ir/x/w/llvm-project/= -no-canonical-prefixes 
> -Wall -std=c++14 -Wno-unused-parameter -O2 -g -DNDEBUG-fPIC -fno-builtin 
> -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector 
> -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only 
> -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -fPIC 
> -ffreestanding -DHWASAN_ALIASING_MODE -UNDEBUG -MD -MT 
> compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
>  -MF 
> compiler-rt\lib\hwasan\CMakeFiles\RTHwasanAliases.aarch64.dir\hwasan_interceptors.cpp.o.d
>  -o 
> compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
>  -c 
> C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
>   In file included from 
> C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:18:
>   C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan.h:41:6: error: 
> Aliasing mode is only supported on x86_64
>
> The error message to the full build:
> https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/build/stdout
>
> The CMake commands:
> https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/configure/execution_details
>
> @morehouse do you have any idea?

Looks like the same issue I fixed in https://reviews.llvm.org/rGd97bab651185.  
Let me know if you have the issue after that commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

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


[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

We started seeing test failures in our Windows builds in Fuchsia after this 
patch.

  FAILED: 
compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
 
  C:\b\s\w\ir\x\w\staging\llvm_build\.\bin\clang++.exe 
--target=aarch64-unknown-linux-gnu --sysroot=C:/b/s/w/ir/x/w/cipd/linux  
-DHWASAN_WITH_INTERCEPTORS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-IC:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/.. 
--target=aarch64-unknown-linux-gnu -fPIC -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wstring-conversion -Wmisleading-indentation -fdiagnostics-color 
-ffunction-sections -fdata-sections 
-ffile-prefix-map=C:/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins=../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins
 -ffile-prefix-map=C:/b/s/w/ir/x/w/llvm-project/= -no-canonical-prefixes -Wall 
-std=c++14 -Wno-unused-parameter -O2 -g -DNDEBUG-fPIC -fno-builtin 
-fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector 
-fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only 
-Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -fPIC 
-ffreestanding -DHWASAN_ALIASING_MODE -UNDEBUG -MD -MT 
compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
 -MF 
compiler-rt\lib\hwasan\CMakeFiles\RTHwasanAliases.aarch64.dir\hwasan_interceptors.cpp.o.d
 -o 
compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
 -c C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
  In file included from 
C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:18:
  C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan.h:41:6: error: 
Aliasing mode is only supported on x86_64

The error message to the full build:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/build/stdout

The CMake commands:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/configure/execution_details

@morehouse do you have any idea?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

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


[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Matt Morehouse 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 rG5f58322368b0: [HWASan] Build separate LAM runtime on x86_64. 
(authored by morehouse).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
  compiler-rt/lib/hwasan/hwasan_linux.cpp

Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -76,7 +76,7 @@
 uptr kHighMemStart;
 uptr kHighMemEnd;
 
-uptr kAliasRegionStart;  // Always 0 on non-x86.
+uptr kAliasRegionStart;  // Always 0 when aliases aren't used.
 
 static void PrintRange(uptr start, uptr end, const char *name) {
   Printf("|| [%p, %p] || %.*s ||\n", (void *)start, (void *)end, 10, name);
@@ -125,33 +125,50 @@
   if (internal_iserror(internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0),
_errno) &&
   local_errno == EINVAL) {
-#if SANITIZER_ANDROID || defined(__x86_64__)
+#  if SANITIZER_ANDROID || defined(HWASAN_ALIASING_MODE)
 // Some older Android kernels have the tagged pointer ABI on
 // unconditionally, and hence don't have the tagged-addr prctl while still
 // allow the ABI.
 // If targeting Android and the prctl is not around we assume this is the
 // case.
 return;
-#else
+#  else
 if (flags()->fail_without_syscall_abi) {
   Printf(
   "FATAL: "
   "HWAddressSanitizer requires a kernel with tagged address ABI.\n");
   Die();
 }
-#endif
+#  endif
   }
 
   // Turn on the tagged address ABI.
   if ((internal_iserror(internal_prctl(PR_SET_TAGGED_ADDR_CTRL,
PR_TAGGED_ADDR_ENABLE, 0, 0, 0)) ||
-   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) &&
-  flags()->fail_without_syscall_abi) {
-Printf(
-"FATAL: HWAddressSanitizer failed to enable tagged address syscall "
-"ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
-"configuration.\n");
-Die();
+   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))) {
+#  if defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+// Try the new prctl API for Intel LAM.  The API is based on a currently
+// unsubmitted patch to the Linux kernel (as of May 2021) and is thus
+// subject to change.  Patch is here:
+// https://lore.kernel.org/linux-mm/20210205151631.43511-12-kirill.shute...@linux.intel.com/
+int tag_bits = kTagBits;
+int tag_shift = kAddressTagShift;
+if (!internal_iserror(
+internal_prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE,
+   reinterpret_cast(_bits),
+   reinterpret_cast(_shift), 0))) {
+  CHECK_EQ(tag_bits, kTagBits);
+  CHECK_EQ(tag_shift, kAddressTagShift);
+  return;
+}
+#  endif  // defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+if (flags()->fail_without_syscall_abi) {
+  Printf(
+  "FATAL: HWAddressSanitizer failed to enable tagged address syscall "
+  "ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
+  "configuration.\n");
+  Die();
+}
   }
 #undef PR_SET_TAGGED_ADDR_CTRL
 #undef PR_GET_TAGGED_ADDR_CTRL
@@ -181,7 +198,7 @@
   // High memory starts where allocated shadow allows.
   kHighMemStart = ShadowToMem(kHighShadowStart);
 
-#if defined(__x86_64__)
+#  if defined(HWASAN_ALIASING_MODE)
   constexpr uptr kAliasRegionOffset = 1ULL << (kTaggableRegionCheckShift - 1);
   kAliasRegionStart =
   __hwasan_shadow_memory_dynamic_address + kAliasRegionOffset;
@@ -191,7 +208,7 @@
   CHECK_EQ(
   (kAliasRegionStart + kAliasRegionOffset - 1) >> kTaggableRegionCheckShift,
   __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
-#endif
+#  endif
 
   // Check the sanity of the defined memory ranges (there might be gaps).
   CHECK_EQ(kHighMemStart % GetMmapGranularity(), 0);
@@ -236,9 +253,11 @@
 }
 
 bool MemIsApp(uptr p) {
-#if !defined(__x86_64__)  // Memory outside the alias range has non-zero tags.
+// Memory outside the alias range has non-zero tags.
+#  if !defined(HWASAN_ALIASING_MODE)
   CHECK(GetTagFromPointer(p) == 0);
-#endif
+#  endif
+
   return p >= kHighMemStart || (p >= kLowMemStart && p <= kLowMemEnd);
 }
 
Index: compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
===
--- compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
+++ compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
@@ -119,12 +119,12 @@
 void InitShadowGOT() {}
 
 uptr 

[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-13 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse updated this revision to Diff 345282.
morehouse added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Rebase onto D102288 .
- Refactor to make LAM the default runtime.
- Use alias runtime if specified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
  compiler-rt/lib/hwasan/hwasan_linux.cpp

Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -76,7 +76,7 @@
 uptr kHighMemStart;
 uptr kHighMemEnd;
 
-uptr kAliasRegionStart;  // Always 0 on non-x86.
+uptr kAliasRegionStart;  // Always 0 when aliases aren't used.
 
 static void PrintRange(uptr start, uptr end, const char *name) {
   Printf("|| [%p, %p] || %.*s ||\n", (void *)start, (void *)end, 10, name);
@@ -125,33 +125,50 @@
   if (internal_iserror(internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0),
_errno) &&
   local_errno == EINVAL) {
-#if SANITIZER_ANDROID || defined(__x86_64__)
+#  if SANITIZER_ANDROID || defined(HWASAN_ALIASING_MODE)
 // Some older Android kernels have the tagged pointer ABI on
 // unconditionally, and hence don't have the tagged-addr prctl while still
 // allow the ABI.
 // If targeting Android and the prctl is not around we assume this is the
 // case.
 return;
-#else
+#  else
 if (flags()->fail_without_syscall_abi) {
   Printf(
   "FATAL: "
   "HWAddressSanitizer requires a kernel with tagged address ABI.\n");
   Die();
 }
-#endif
+#  endif
   }
 
   // Turn on the tagged address ABI.
   if ((internal_iserror(internal_prctl(PR_SET_TAGGED_ADDR_CTRL,
PR_TAGGED_ADDR_ENABLE, 0, 0, 0)) ||
-   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) &&
-  flags()->fail_without_syscall_abi) {
-Printf(
-"FATAL: HWAddressSanitizer failed to enable tagged address syscall "
-"ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
-"configuration.\n");
-Die();
+   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))) {
+#  if defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+// Try the new prctl API for Intel LAM.  The API is based on a currently
+// unsubmitted patch to the Linux kernel (as of May 2021) and is thus
+// subject to change.  Patch is here:
+// https://lore.kernel.org/linux-mm/20210205151631.43511-12-kirill.shute...@linux.intel.com/
+int tag_bits = kTagBits;
+int tag_shift = kAddressTagShift;
+if (!internal_iserror(
+internal_prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE,
+   reinterpret_cast(_bits),
+   reinterpret_cast(_shift), 0))) {
+  CHECK_EQ(tag_bits, kTagBits);
+  CHECK_EQ(tag_shift, kAddressTagShift);
+  return;
+}
+#  endif  // defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+if (flags()->fail_without_syscall_abi) {
+  Printf(
+  "FATAL: HWAddressSanitizer failed to enable tagged address syscall "
+  "ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
+  "configuration.\n");
+  Die();
+}
   }
 #undef PR_SET_TAGGED_ADDR_CTRL
 #undef PR_GET_TAGGED_ADDR_CTRL
@@ -181,7 +198,7 @@
   // High memory starts where allocated shadow allows.
   kHighMemStart = ShadowToMem(kHighShadowStart);
 
-#if defined(__x86_64__)
+#  if defined(HWASAN_ALIASING_MODE)
   constexpr uptr kAliasRegionOffset = 1ULL << (kTaggableRegionCheckShift - 1);
   kAliasRegionStart =
   __hwasan_shadow_memory_dynamic_address + kAliasRegionOffset;
@@ -191,7 +208,7 @@
   CHECK_EQ(
   (kAliasRegionStart + kAliasRegionOffset - 1) >> kTaggableRegionCheckShift,
   __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
-#endif
+#  endif
 
   // Check the sanity of the defined memory ranges (there might be gaps).
   CHECK_EQ(kHighMemStart % GetMmapGranularity(), 0);
@@ -236,9 +253,11 @@
 }
 
 bool MemIsApp(uptr p) {
-#if !defined(__x86_64__)  // Memory outside the alias range has non-zero tags.
+// Memory outside the alias range has non-zero tags.
+#  if !defined(HWASAN_ALIASING_MODE)
   CHECK(GetTagFromPointer(p) == 0);
-#endif
+#  endif
+
   return p >= kHighMemStart || (p >= kLowMemStart && p <= kLowMemEnd);
 }
 
Index: compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
===
--- compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
+++ compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
@@ -119,12 +119,12 @@
 void