[PATCH] D58195: [HWASAN] Updated HWASAN design document to better portray the chance of missing a bug.

2019-02-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Provided rule of thumb percentage chances of miss for 4 and 8 bit tag sizes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58195

Files:
  clang/docs/HardwareAssistedAddressSanitizerDesign.rst


Index: clang/docs/HardwareAssistedAddressSanitizerDesign.rst
===
--- clang/docs/HardwareAssistedAddressSanitizerDesign.rst
+++ clang/docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -131,7 +131,8 @@
 https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt).
   * **Does not require redzones to detect buffer overflows**,
 but the buffer overflow detection is probabilistic, with roughly
-`(2**TS-1)/(2**TS)` probability of catching a bug.
+`1/(2**TS)` chance of missing a bug (6.25% or 0.39% with 4 and 8-bit TS
+respectively).
   * **Does not require quarantine to detect heap-use-after-free,
 or stack-use-after-return**.
 The detection is similarly probabilistic.


Index: clang/docs/HardwareAssistedAddressSanitizerDesign.rst
===
--- clang/docs/HardwareAssistedAddressSanitizerDesign.rst
+++ clang/docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -131,7 +131,8 @@
 https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt).
   * **Does not require redzones to detect buffer overflows**,
 but the buffer overflow detection is probabilistic, with roughly
-`(2**TS-1)/(2**TS)` probability of catching a bug.
+`1/(2**TS)` chance of missing a bug (6.25% or 0.39% with 4 and 8-bit TS
+respectively).
   * **Does not require quarantine to detect heap-use-after-free,
 or stack-use-after-return**.
 The detection is similarly probabilistic.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58195: [HWASAN] Updated HWASAN design document to better portray the chance of missing a bug.

2019-02-13 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC353990: [HWASAN] Updated HWASAN design document to better 
portray the chance of missing… (authored by hctim, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58195?vs=186695&id=186754#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D58195

Files:
  docs/HardwareAssistedAddressSanitizerDesign.rst


Index: docs/HardwareAssistedAddressSanitizerDesign.rst
===
--- docs/HardwareAssistedAddressSanitizerDesign.rst
+++ docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -131,7 +131,8 @@
 https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt).
   * **Does not require redzones to detect buffer overflows**,
 but the buffer overflow detection is probabilistic, with roughly
-`(2**TS-1)/(2**TS)` probability of catching a bug.
+`1/(2**TS)` chance of missing a bug (6.25% or 0.39% with 4 and 8-bit TS
+respectively).
   * **Does not require quarantine to detect heap-use-after-free,
 or stack-use-after-return**.
 The detection is similarly probabilistic.


Index: docs/HardwareAssistedAddressSanitizerDesign.rst
===
--- docs/HardwareAssistedAddressSanitizerDesign.rst
+++ docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -131,7 +131,8 @@
 https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt).
   * **Does not require redzones to detect buffer overflows**,
 but the buffer overflow detection is probabilistic, with roughly
-`(2**TS-1)/(2**TS)` probability of catching a bug.
+`1/(2**TS)` chance of missing a bug (6.25% or 0.39% with 4 and 8-bit TS
+respectively).
   * **Does not require quarantine to detect heap-use-after-free,
 or stack-use-after-return**.
 The detection is similarly probabilistic.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-30 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 202237.
hctim marked 7 inline comments as done.
hctim added a comment.

- Updated from Matt's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_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.in
+${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+  list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+endforeach

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-30 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: compiler-rt/lib/gwp_asan/tests/driver.cpp:14
+  return RUN_ALL_TESTS();
+}

morehouse wrote:
> hctim wrote:
> > morehouse wrote:
> > > Can we just link with gtest_main instead of having this?
> > Unfortunately not easily. `generate_compiler_rt_tests` builds each test cpp 
> > file individually, and provides no way to add `gtest_main` only during link 
> > time. 
> Then how does this driver.cpp get included in each unit test?
> 
> Maybe we should put the `main` in each test as is usually done.
Basically what happens:
```
for x in *.cpp;
  do clang++ $x -o $x.o
done
clang++ *.o -o GwpAsanUnitTests
```

The unittests are all packaged together into a single binary. Also, AFAIK, 
compiler-rt all has a single `main()` driver for unittests (at least 
ASan+MSan+Scudo do this).



Comment at: compiler-rt/lib/gwp_asan/tests/mutex_test.cpp:102
+TEST(GwpAsanMutexTest, ThrashTests) {
+  runThrashTest(2, 1);
+  runThrashTest(4, 1);

morehouse wrote:
> morehouse wrote:
> > This test case seems to test a superset of ThreadedConstructionTest, so do 
> > we really need that one?
> This test case seems to test a superset of ThreadedConstructionTest, so do we 
> really need that one?
Deleted ThreadedLockUnlockTest.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923



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


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-30 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 202275.
hctim added a comment.

Merged with tip-of-tree in preparation for submit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_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.in
+${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+  list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+endforeach()
+
+add_lit_testsui

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-30 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL362138: [GWP-ASan] Mutex implementation [2]. (authored by 
hctim, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D61923?vs=202275&id=202276#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61923

Files:
  cfe/trunk/runtime/CMakeLists.txt
  compiler-rt/trunk/lib/gwp_asan/CMakeLists.txt
  compiler-rt/trunk/lib/gwp_asan/mutex.h
  compiler-rt/trunk/lib/gwp_asan/platform_specific/mutex_posix.cpp
  compiler-rt/trunk/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/trunk/lib/gwp_asan/tests/driver.cpp
  compiler-rt/trunk/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/trunk/test/gwp_asan/CMakeLists.txt
  compiler-rt/trunk/test/gwp_asan/dummy_test.cc
  compiler-rt/trunk/test/gwp_asan/lit.cfg
  compiler-rt/trunk/test/gwp_asan/lit.site.cfg.in
  compiler-rt/trunk/test/gwp_asan/unit/lit.site.cfg.in

Index: cfe/trunk/runtime/CMakeLists.txt
===
--- cfe/trunk/runtime/CMakeLists.txt
+++ cfe/trunk/runtime/CMakeLists.txt
@@ -132,7 +132,7 @@
 # Add top-level targets for various compiler-rt test suites.
 set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-hwasan check-asan-dynamic check-dfsan
   check-lsan check-msan check-sanitizer check-tsan check-ubsan check-ubsan-minimal
-  check-profile check-cfi check-cfi-and-supported check-safestack)
+  check-profile check-cfi check-cfi-and-supported check-safestack check-gwp_asan)
 foreach(test_suite ${COMPILER_RT_TEST_SUITES})
   get_ext_project_build_command(run_test_suite ${test_suite})
   add_custom_target(${test_suite}
Index: compiler-rt/trunk/test/gwp_asan/unit/lit.site.cfg.in
===
--- compiler-rt/trunk/test/gwp_asan/unit/lit.site.cfg.in
+++ compiler-rt/trunk/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/trunk/test/gwp_asan/lit.site.cfg.in
===
--- compiler-rt/trunk/test/gwp_asan/lit.site.cfg.in
+++ compiler-rt/trunk/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/trunk/test/gwp_asan/dummy_test.cc
===
--- compiler-rt/trunk/test/gwp_asan/dummy_test.cc
+++ compiler-rt/trunk/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/trunk/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/trunk/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/trunk/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_TEST_TARGET_CFLAGS)
+  string(TOUPPER ${arch} ARCH_UPPER_CASE)
+  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
+
+  configure_lit_site_c

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-30 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Looks like this broke an autoconf bot 
.
 Have submitted rL362149 , which should 
hopefully fix the issue.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61923



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


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-30 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Looks like this also broke an armv8 bot, due to a maximum number of threads 
issue. Have filed rL362163  to attempt to 
fix. If that doesn't work, I'll just disable the test for armv8.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61923



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


[PATCH] D60593: [GwpAsan] Introduce GWP-ASan.

2019-06-28 Thread Mitch Phillips via Phabricator via cfe-commits
hctim abandoned this revision.
hctim added a comment.

Abandoned as this was merged in small chunks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60593



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


[PATCH] D60593: [GwpAsan] Introduce GWP-ASan.

2019-05-10 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 199083.
hctim marked an inline comment as done.
hctim added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Updated tests to use unittests rather than expose a public interface and 
exercise that. Minor perf improvements to shouldSample().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60593

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/definitions.h
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  compiler-rt/lib/gwp_asan/guarded_pool_allocator_posix.cpp
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/optional/options_parser.cpp
  compiler-rt/lib/gwp_asan/optional/options_parser.h
  compiler-rt/lib/gwp_asan/options.h
  compiler-rt/lib/gwp_asan/options.inc
  compiler-rt/lib/gwp_asan/random.cpp
  compiler-rt/lib/gwp_asan/random.h
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/alignment.cpp
  compiler-rt/lib/gwp_asan/tests/basic.cpp
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/harness.h
  compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp
  compiler-rt/lib/gwp_asan/tests/thread_contention.cpp
  compiler-rt/lib/scudo/CMakeLists.txt
  compiler-rt/lib/scudo/scudo_allocator.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/allocation_methods.cpp
  compiler-rt/test/gwp_asan/allocator_fallback.cpp
  compiler-rt/test/gwp_asan/double_delete.cpp
  compiler-rt/test/gwp_asan/double_deletea.cpp
  compiler-rt/test/gwp_asan/double_free.cpp
  compiler-rt/test/gwp_asan/heap_buffer_overflow.cpp
  compiler-rt/test/gwp_asan/heap_buffer_underflow.cpp
  compiler-rt/test/gwp_asan/invalid_free_left.cpp
  compiler-rt/test/gwp_asan/invalid_free_right.cpp
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/page_size.h
  compiler-rt/test/gwp_asan/repeated_alloc.cpp
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
  compiler-rt/test/gwp_asan/use_after_delete.cpp
  compiler-rt/test/gwp_asan/use_after_deletea.cpp
  compiler-rt/test/gwp_asan/use_after_free.cpp
  compiler-rt/test/lit.common.cfg
  compiler-rt/test/lit.common.configured.in
  compiler-rt/test/scudo/lit.cfg
  llvm/docs/GwpAsan.rst

Index: llvm/docs/GwpAsan.rst
===
--- /dev/null
+++ llvm/docs/GwpAsan.rst
@@ -0,0 +1,189 @@
+
+GWP-ASan
+
+
+.. contents::
+   :local:
+   :depth: 2
+
+Introduction
+
+
+GWP-ASan is a sampled allocator framework that assists in finding use-after-free
+and heap-buffer-overflow bugs in production environments. It informally is a
+recursive acronym, "**G**\WP-ASan **W**\ill **P**\rovide **A**\llocation
+**SAN**\ity".
+
+GWP-ASan is based on the classic
+`Electric Fence Malloc Debugger `_, with a
+key adaptation. Notably, we only choose a very small percentage of allocations
+to sample, and apply guard pages to these sampled allocations only. The sampling
+is small enough to allow us to have very low performance overhead.
+
+There is a small, tunable memory overhead that is fixed for the lifetime of the
+process. This is approximately ~60KiB per process using the default settings,
+depending on the average size of your allocations. Future improvements should
+drastically reduce this amount.
+
+GWP-ASan vs. ASan
+=
+
+Unlike `AddressSanitizer `_,
+GWP-ASan does not induce a significant performance overhead. ASan often requires
+the use of dedicated canaries to be viable in production environments, and as
+such is often impractical.
+
+GWP-ASan is only capable of finding a subset of the memory issues detected by
+ASan. Furthermore, GWP-ASan's bug detection capabilities are only probabilistic.
+As such, we recommend using ASan over GWP-ASan in testing, as well as anywhere
+else that guaranteed error detection is more valuable than the 2x execution
+slowdown/binary size bloat. For the majority of production environments, this
+impact is too high, and GWP-ASan proves extremely useful.
+
+Design
+==
+
+**Please note:** The implementation of GWP-ASan is largely in-flux, and these
+details are subject to change. There are currently other implementations of
+GWP-ASan, such as the implementation featured in
+`Chromium `_. The
+long-term support goal is to ensure feature-parity where reasonble, and to
+support compiler-rt as the reference implementation.
+
+Allocator Support
+-
+
+GWP-ASan is not a replacement for a traditional allocator. Instead, it works by
+inserting stubs into an existing allocator to redirect allocations when th

[PATCH] D60593: [GwpAsan] Introduce GWP-ASan.

2019-05-10 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D60593#1495428 , @gribozavr wrote:

> What does GWP stand for?


Google Wide Profiling 
.

We use the name GWP-ASan, even though it's "technically neither GWP nor ASan", 
but because it describes well what the outcome is (sampled allocations with 
memory detection capabilities). It also mirrors the name used for the identical 
mechanism implemented in Chromium 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60593



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


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-14 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 199541.
hctim marked 10 inline comments as done.
hctim added a comment.
Herald added subscribers: cfe-commits, srhines.
Herald added a reviewer: jfb.
Herald added a project: clang.

- Working copy of mutex.
- >>! In D61923#1502245 , @jfb wrote:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/definitions.h
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_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.si

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-14 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D61923#1502245 , @jfb wrote:

> Seems a shame to duplicate mutex again... Why can't use use the STL's version 
> again? It doesn't allocate.


We can't use `std::mutex` as we must be C-compatible (and can't make the strong 
guarantee that `std::mutex` is header-only), see 
https://reviews.llvm.org/D60593#inline-537276.
We also are trying to stay independent of `pthread` for 
platform-independentness.
We also can't use a `sanitizer_common` variant as we don't want to pull in the 
entirety `sanitizer_common` as a dependency.

Basically, the roadmap is to create a shared mutex library for 
`sanitizer_common`, `gwp_asan` and `scudo` to all use.

In D61923#1502245 , @jfb wrote:

> Tests?


Added some unit tests.




Comment at: compiler-rt/lib/gwp_asan/mutex.h:32
+private:
+  void yieldProcessor(uint8_t Count);
+  void yieldPlatform();

jfb wrote:
> `uint8_t` seems easy to inadvertently truncate. If you want to restrict size, 
> make it a template and refuse to compile above a certain size. It's always 
> `10` anyways.
Seeming as this is an entirely-internal number, I've made it a global instead.



Comment at: compiler-rt/lib/gwp_asan/mutex.h:81
+else
+  yieldPlatform();
+

jfb wrote:
> This won't compile if `__unix__` isn't defined.
Should be guarded by `if (COMPILER_RT_HAS_GWP_ASAN)` at 
`lib/gwp_asan/CMakeLists.txt:20`, but have added explicit error condition here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923



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


[PATCH] D60593: [GwpAsan] Introduce GWP-ASan.

2019-05-14 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D60593#1502266 , @jfb wrote:

> Hello I'm here to bikeshed, and this is a terrible name for an LLVM project. 
> Or super appropriate because LLVM itself is a terrible name? In any case, 
> backronym it to something else, or rename it. Thanks!


Also see `GwpAsan.rst`:

> It informally is a recursive acronym, "**G**WP-ASan **W**ill **P**rovide 
> **A**llocation **SAN**ity".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60593



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


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 199632.
hctim marked 2 inline comments as done.
hctim added a comment.

In D61923#1502988 , @cryptoad wrote:

> Is the question why do Scudo has its own as opposed to rely on platform 
> specific ones?


Yes, I have assumptions about why, but would love to hear right from the 
horse's mouth :)

In D61923#1502404 , @jfb wrote:

> > We can't use `std::mutex` as we must be C-compatible
>
> Can you clarify what you mean by this? I don't understand.
>  Have you asked on libcxx-dev? Is there interest in the libc++ community for 
> a stand-alone base?


Sorry, poor choice of wording. Our archive must be able to be statically linked 
into the supporting allocators. At this stage, the plans are to implement 
GWP-ASan into Scudo and Android's bionic libc. This means we have to be 
compatible with the the most restrictive aspects of each allocator's build 
environment, simultaneously.

In practice, we can't use `std::mutex` because Scudo specifies `-nostdlib++ 
-nodefaultlibs`, and if any part of the implementation of `std::mutex` (and 
likewise `mtx_t`) falls outside of the header file, we will fail to link (as is 
the case with libc++).

>> We also are trying to stay independent of `pthread` for 
>> platform-independentness.
> 
> The code I see is clearly not platform independent. Please clarify your 
> reasoning. I can understand if you don't want pthread for a valid reason, but 
> "platform-independence" doesn't make sense here.

My view was that small stubs to implement the architecture-dependent and 
OS-dependent functionality is much easier to manage. If we use `pthread` on 
unix, and `CreateMutex` on Windows, we still have to have OS-dependent ifdefs, 
but we then pass on the requirement to the supporting allocator to ensure our 
dependencies are there (which could be a huge pain point both for Scudo+fuchsia 
and Android).

>> We also can't use a `sanitizer_common` variant as we don't want to pull in 
>> the entirety `sanitizer_common` as a dependency.
> 
> What's the restriction that makes it unacceptable?

Scudo (standalone) can't pull in the entirety of sanitizer_common (code size + 
maintainability for fuchsia). It's also a much easier track to get Android 
supported if we don't have to pull in and build the entirety of 
sanitizer_common.

>> Basically, the roadmap is to create a shared mutex library for 
>> `sanitizer_common`, `gwp_asan` and `scudo` to all use.
> 
> I'm asking all these question because they should be in the commit message, 
> and would hopefully have surfaced from the RFC about GWP / Scudo. If those 
> weren't in the RFC that's fine, they should still be in the commit message 
> and you'll want to update the RFC with "while reviewing code we realized 
> *stuff*".

Ack.

>> I think the idea is that implementing our own spinlock is not much harder 
>> than having 3 platform-specific implementations (posix, window, fuchsia).
> 
> Your concerns are backwards. Implementation is a one-time thing, maintenance 
> is an ongoing concern and it way overshadows implementation concerns. In 
> particular, a variety of multicore code that does its own locking is much 
> harder to tune at the system-wide level compared to a single thing that's 
> tuned for each application. I'm not saying a separate mutex doesn't make 
> sense, what I'm saying is that experience shows your above reasoning to be 
> generally invalid. I'm totally willing to believe that there's a very good 
> reason to have your own mutex here, but you gotta explain it.

Hopefully above helps to clarify :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/definitions.h
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
==

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D61923#1503272 , @jfb wrote:

> Have you asked on libcxx-dev whether a stand-alone base is something of 
> interest to them?


No, but I will follow up on that.

> Kinda... but your answer really sounds like this is a Google-only project, 
> with intended uses only for some Google applications. That's not necessarily 
> a bad thing, but it's really weird: my impression was that GWP and Scudo were 
> intended to be generally usable elsewhere. Is that not the case?
> 
> Not that I expect *you* to do any porting work, but the direction you're 
> setting just sounds like "well, we're our only users and we'll take the path 
> that'll work for us". None of the reasoning seems to be truly technical, it's 
> more "these projects we want to integrate into build this way, so we should 
> fit in that way". i.e. it's more about implementation convenience than 
> anything else. Is that the case? Implementation convenience is sometimes a 
> good reason, but as I've outlined above I think you need to provide more 
> thoughtful reasoning.

I definitely don't want that to be the case, or to have it come across that 
way. We want a reference implementation that's available for any allocator to 
drop in and use, with minor tweaking. As part of that, our goal is to make the 
requirements to support GWP-ASan as low as possible, preferably as simple as 
"merge this into your codebase somewhere, and you're good to go". We inherit 
the restrictions of each allocator's build system, which means more restrictive 
environment for us, but we can be drop-in supported pretty much everywhere. Our 
plans for this reference implementation is to use it in Android and Fuchsia, 
but we would love to collaborate with other interested projects to hear about 
what their requirements would be as well.

We discussed at length whether to have GWP-ASan be a standalone GitHub project 
(similar to Scudo standalone), or as part of compiler-rt. We decided to put it 
into compiler-rt because we can then exercise LLVM's extensive 
build/test/review infrastructure and open-source licensing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923



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


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 200094.
hctim added a comment.

Merged in master after fixing up some buildbots with the previous patches.

Also have pinged libcxx-dev :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/definitions.h
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_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.in
+${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+  list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAM

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 200600.
hctim added a comment.

Changed GWP-ASan to use platform specific mutexes. For now, we only
target Android and Linux, and subsequently only need the pthread_mutex
variant for POSIX.

Kept around the mutex unittests as it's an easy assertion that the
abstraction over the platform specifics is implemented correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/platform_specific/mutex_include.h
  compiler-rt/lib/gwp_asan/platform_specific/mutex_members.inc
  compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_TEST

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 200604.
hctim marked an inline comment as done.
hctim added a comment.

- Updated to use pointer-to-impl to abstract implementation behaviour away from 
header files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_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.in
+${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+  list(APPEND GWP_ASAN_TES

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-22 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp:43
+
+Mutex::Mutex() : PImpl(new Impl) {}
+Mutex::~Mutex() { delete PImpl; }

eugenis wrote:
> This is a dependency on libc++ / libstdc++.
> 
> I'm not sure about using malloc() inside mutex constructor, either.
> 
> We will probably want the mutex to be linker-initialized, too. AFAIK, 
> gwp-asan would not have any clear initialization entry point, and would need 
> to do this lazily in malloc, which can there be several of, concurrently.
> 
As per offline discussion, have ifdef-d the platform-specific headers into this 
file. Allows us to have linker initialisation (at least for POSIX).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923



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


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-22 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 200760.
hctim marked 2 inline comments as done.
hctim added a comment.

- Ifdef-d headers into mutex.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_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.in
+${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+  list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+endforeach(

[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-29 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: compiler-rt/lib/gwp_asan/tests/driver.cpp:14
+  return RUN_ALL_TESTS();
+}

morehouse wrote:
> Can we just link with gtest_main instead of having this?
Unfortunately not easily. `generate_compiler_rt_tests` builds each test cpp 
file individually, and provides no way to add `gtest_main` only during link 
time. 



Comment at: compiler-rt/lib/gwp_asan/tests/mutex_test.cpp:46
+  while (!StartingGun->load())
+;
+  for (unsigned i = 0; i < kNumLocksInARow; ++i) {

morehouse wrote:
> Format seems weird.  Does clang-format let us do `while (...) {}` on one line?
CF changes it to 
```
while (!StartingGun) {
}
```



Comment at: compiler-rt/test/gwp_asan/CMakeLists.txt:1
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

morehouse wrote:
> Can the lit test stuff go in another patch when we actually have tests?
Not AFAIK. The unit tests are actually invoked through the lit configurations 
in this directory.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923



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


[PATCH] D61923: [GWP-ASan] Mutex implementation [2].

2019-05-29 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 202078.
hctim marked 21 inline comments as done.
hctim added a comment.

- Apologies about the delay on this. Updated with Matt's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61923

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/gwp_asan/CMakeLists.txt
  compiler-rt/lib/gwp_asan/mutex.h
  compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp
  compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
  compiler-rt/lib/gwp_asan/tests/driver.cpp
  compiler-rt/lib/gwp_asan/tests/mutex_test.cpp
  compiler-rt/test/gwp_asan/CMakeLists.txt
  compiler-rt/test/gwp_asan/dummy_test.cc
  compiler-rt/test/gwp_asan/lit.cfg
  compiler-rt/test/gwp_asan/lit.site.cfg.in
  compiler-rt/test/gwp_asan/unit/lit.site.cfg.in

Index: compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name = "GwpAsan-Unittest"
+# Load common config for all compiler-rt unit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
+
+config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
+ "lib", "gwp_asan", "tests")
+config.test_source_root = config.test_exec_root
Index: compiler-rt/test/gwp_asan/lit.site.cfg.in
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.site.cfg.in
@@ -0,0 +1,11 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+config.name_suffix = "@GWP_ASAN_TEST_CONFIG_SUFFIX@"
+config.target_arch = "@GWP_ASAN_TEST_TARGET_ARCH@"
+config.target_cflags = "@GWP_ASAN_TEST_TARGET_CFLAGS@"
+
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@GWP_ASAN_LIT_SOURCE_DIR@/lit.cfg")
Index: compiler-rt/test/gwp_asan/lit.cfg
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/lit.cfg
@@ -0,0 +1,31 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'GWP-ASan' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp', '.test']
+
+# C & CXX flags.
+c_flags = ([config.target_cflags])
+
+# Android doesn't want -lrt.
+if not config.android:
+  c_flags += ["-lrt"]
+
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+# Add substitutions.
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+
+# GWP-ASan tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+   config.unsupported = True
Index: compiler-rt/test/gwp_asan/dummy_test.cc
===
--- /dev/null
+++ compiler-rt/test/gwp_asan/dummy_test.cc
@@ -0,0 +1,4 @@
+// Exists to simply stop warnings about lit not discovering any tests here.
+// RUN: %clang %s
+
+int main() { return 0; }
Index: compiler-rt/test/gwp_asan/CMakeLists.txt
===
--- compiler-rt/test/gwp_asan/CMakeLists.txt
+++ compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(GWP_ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(GWP_ASAN_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+set(GWP_ASAN_TESTSUITES)
+
+set(GWP_ASAN_UNITTEST_DEPS)
+set(GWP_ASAN_TEST_DEPS
+  ${SANITIZER_COMMON_LIT_TEST_DEPS}
+  gwp_asan)
+
+if (COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
+  configure_lit_site_cfg(
+${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-gwp_asan-unit "Running GWP-ASan unit tests"
+${CMAKE_CURRENT_BINARY_DIR}/unit
+DEPENDS ${GWP_ASAN_TEST_DEPS})
+  set_target_properties(check-gwp_asan-unit PROPERTIES FOLDER
+"Compiler-RT Tests")
+list(APPEND GWP_ASAN_TEST_DEPS check-gwp_asan-unit)
+endif()
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_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.in
+${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+  list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BIN

[PATCH] D83987: [libFuzzer] Disable implicit builtin knowledge about memcmp-like functions when -fsanitize=fuzzer-no-link is given.

2020-07-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim accepted this revision.
hctim added a comment.
This revision is now accepted and ready to land.

LGTM w/ nit




Comment at: clang/lib/Driver/SanitizerArgs.cpp:1091
 
+  if (Sanitizers.has(SanitizerKind::FuzzerNoLink)) {
+CmdArgs.push_back("-fno-builtin-memcmp");

Nit - add a comment here mentioning the libfuzzer interceptors, and that other 
sanitizers normally do this by propagating IR attributes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83987



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


[PATCH] D83987: [libFuzzer] Disable implicit builtin knowledge about memcmp-like functions when -fsanitize=fuzzer-no-link is given.

2020-07-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:1092
+  // libFuzzer wants to intercept calls to certain library functions, so the
+  // following -fno-builtin-* flags disable implicit builtin knowledge about
+  // those functions. Other sanitizers effectively do the same thing by marking

I'd say "the following -fno-builtin-* flags force the compiler to emit 
interposable libcalls to these functions"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83987



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


[PATCH] D83987: [libFuzzer] Disable implicit builtin knowledge about memcmp-like functions when -fsanitize=fuzzer-no-link is given.

2020-07-16 Thread Mitch Phillips via Phabricator via cfe-commits
hctim accepted this revision.
hctim added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83987



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


[PATCH] D82926: [libfuzzer] [clang] Add __has_feature(fuzzing_coverage)

2020-07-01 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

So - the `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` flag is a property of the 
build system and not that of the compiler. There are some places (android) 
where enabling `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` globally changes the 
behaviour of large amounts of libraries in ways that break the build system.

Having this flag allows us to make targeted compile-time changes to libc based 
on sancov that don't require enabling 
`FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` across the entire build system.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82926



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


[PATCH] D83369: hwasan: Don't pass the tagged-globals target-feature to non-aarch64 backends.

2020-07-08 Thread Mitch Phillips via Phabricator via cfe-commits
hctim accepted this revision.
hctim added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83369



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


[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

2020-07-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D83494#2147608 , @dokyungs wrote:

> Builtin libfunc optimizations may transform memcmp and strcmp-like functions. 
> To disable such optimizations, -fno-builtin= flag was additionally added in 
> compiling new test cases. FWIW, the original test cases didn't require such 
> flags since other sanitizers including ASan disables those optimizations in 
> their LLVM pass by dropping libfunc attribute in the call instructions.


It sounds like we need to add `-fno-builtin` in the clang driver when building 
with sancov as well. Otherwise, users won't get any benefit of this patch 
without doing `clang++ -fsanitize=fuzzer my_fuzz_target.cpp -fno-builtin-strstr 
-fno-builtin-strncmp  -fno-builtin-strcmp  -fno-builtin-memcmp`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83494



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


[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

2020-07-13 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D83494#2148180 , @morehouse wrote:

> In D83494#2148164 , @dokyungs wrote:
>
> > Right. Apparently with `-O2` many calls to `memcmp`-like functions are 
> > removed. I just wondered, though, what makes more sense: disabling such 
> > optimization when building (i) with sancov, or (ii) with 
> > `-fsanitize=fuzzer`? If we go for (i), would it make sense to do it in the 
> > SanitizerCoverage module pass like other sanitizers do? What do you think? 
> > Also, can it be addressed in a follow-up patch?
>
>
> My opinion is to make it part of `-fsanitize=fuzzer`, or maybe disable parts 
> of the builtin optimization pass for functions with the `OptForFuzzing` 
> attribute.
>
> And I think a follow-up patch is easier to review.


Agreed with Matt on all of the above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83494



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


[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

2020-07-14 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:242
+bool SanitizerArgs::needsFuzzerInterceptors() const {
+  return needsFuzzer() && !needsAsanRt() && !needsHwasanRt() &&
+ !needsTsanRt() && !needsMsanRt();

HWASan doesn't have interceptors - we actually want fuzzer interceptors under 
`needsFuzzer() && needsHwasanRt()` (just remove the `!needsHwasanRt()`).



Comment at: compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp:52
+// NOLINTNEXTLINE
+void __sanitizer_weak_hook_memcmp(void *, const void *, const void *, size_t,
+  int);

Why not `#include ` (and below)?



Comment at: compiler-rt/lib/fuzzer/FuzzerPlatform.h:1
-//===- FuzzerDefs.h - Internal header for the Fuzzer *- C++ -* 
===//
+//===-- FuzzerInterceptors.cpp 
===//
 //

Nit - name change



Comment at: compiler-rt/lib/fuzzer/FuzzerPlatform.h:8
 
//===--===//
-// Basic definitions.
+//
+// Common platform macros.

Nit - remove blank comment



Comment at: compiler-rt/test/fuzzer/memcmp.test:8
+RUN: not %run %t-MemcmpTest   -seed=1 -runs=1000   2>&1 | 
FileCheck %s --check-prefix=CHECK2
+CHECK2: BINGO

morehouse wrote:
> CHECK1 and CHECK2 is unnecessary.  Let's use the same CHECK for both.
No need to have different `CHECK`'s throughout this patchset (in both tests 
we're checking for the same thing.

```
UNSUPPORTED: freebsd
RUN: %cpp_compiler %S/MemcmpTest.cpp -o %t-MemcmpTest
RUN: not %run %t-MemcmpTest   -seed=1 -runs=1000   2>&1 | 
FileCheck %s

RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-memcmp %S/MemcmpTest.cpp 
-o %t-NoAsanMemcmpTest
RUN: not %run %t-MemcmpTest   -seed=1 -runs=1000   2>&1 | 
FileCheck %s

CHECK: BINGO
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83494



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


[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

2020-07-14 Thread Mitch Phillips via Phabricator via cfe-commits
hctim accepted this revision.
hctim marked an inline comment as done.
hctim added a comment.

LGTM




Comment at: compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp:52
+// NOLINTNEXTLINE
+void __sanitizer_weak_hook_memcmp(void *, const void *, const void *, size_t,
+  int);

hctim wrote:
> Why not `#include ` (and below)?
The comment above is obsolete - please mark as done before closing out the 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83494



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


[PATCH] D82249: [HWASan] Disable GlobalISel/FastISel for HWASan Globals.

2020-06-19 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added reviewers: pcc, ostannard.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits, kristof.beyls, 
rovka.
Herald added projects: clang, Sanitizers, LLVM.

HWASan globals instruction selection lowering hasn't been implemented in
GlobalISel or FastISel. We need to ensure that we get SelectionDAGISel
in all cases where HWASan is enabled.

GlobalISel is the default ISel for aarch64 at -O0. All others go to
SelectionDAGISel. When we disable GlobalISel, we get FastISel, so
disable that too.

Add a regression test to HWASan, and tighten up the instruction
selection test to also include both PIC and static relocation models.

We intend to add lowering for at least GlobalISel at a later date, but this
is a temporary fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82249

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/test/hwasan/TestCases/exported-tagged-global.c
  llvm/test/CodeGen/AArch64/tagged-globals.ll

Index: llvm/test/CodeGen/AArch64/tagged-globals.ll
===
--- llvm/test/CodeGen/AArch64/tagged-globals.ll
+++ llvm/test/CodeGen/AArch64/tagged-globals.ll
@@ -1,31 +1,70 @@
-; RUN: llc < %s | FileCheck %s
+; RUN: llc --relocation-model=static < %s | FileCheck %s
+; RUN: llc --relocation-model=pic < %s | FileCheck %s -check-prefix=CHECK-PIC
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 target triple = "aarch64-unknown-linux-android"
 
-@global = external hidden global i32
+@global = external global i32
 declare void @func()
 
 define i32* @global_addr() #0 {
   ; CHECK: global_addr:
-  ; CHECK: adrp x0, :pg_hi21_nc:global
-  ; CHECK: movk x0, #:prel_g3:global+4294967296
-  ; CHECK: add x0, x0, :lo12:global
+  ; CHECK: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
+  ; CHECK: movk [[REG]], #:prel_g3:global+4294967296
+  ; CHECK: add x0, [[REG]], :lo12:global
+  ; CHECK: ret
+
+  ; CHECK-PIC: global_addr:
+  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
+  ; CHECK-PIC: ldr x0, {{\[}}[[REG]], :got_lo12:global]
+  ; CHECK-PIC: ret
+
   ret i32* @global
 }
 
 define i32 @global_load() #0 {
   ; CHECK: global_load:
-  ; CHECK: adrp x8, :pg_hi21_nc:global
-  ; CHECK: ldr w0, [x8, :lo12:global]
+  ; CHECK: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
+  ; CHECK: ldr w0, {{\[}}[[REG]], :lo12:global{{\]}}
+  ; CHECK: ret
+
+  ; CHECK-PIC: global_load:
+  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
+  ; CHECK-PIC: ldr  [[REG]], {{\[}}[[REG]], :got_lo12:global]
+  ; CHECK-PIC: ldr w0, {{\[}}[[REG]]{{\]}}
+  ; CHECK-PIC: ret
+
   %load = load i32, i32* @global
   ret i32 %load
 }
 
+define void @global_store() #0 {
+  ; CHECK: global_store:
+  ; CHECK: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
+  ; CHECK: str wzr, {{\[}}[[REG]], :lo12:global{{\]}}
+  ; CHECK: ret
+
+  ; CHECK-PIC: global_store:
+  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
+  ; CHECK-PIC: ldr  [[REG]], {{\[}}[[REG]], :got_lo12:global]
+  ; CHECK-PIC: str wzr, {{\[}}[[REG]]{{\]}}
+  ; CHECK-PIC: ret
+
+  store i32 0, i32* @global
+  ret void
+}
+
 define void ()* @func_addr() #0 {
   ; CHECK: func_addr:
-  ; CHECK: adrp x0, func
-  ; CHECK: add x0, x0, :lo12:func
+  ; CHECK: adrp [[REG:x[0-9]+]], func
+  ; CHECK: add x0, [[REG]], :lo12:func
+  ; CHECK: ret
+
+  ; CHECK-PIC: func_addr:
+  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:func
+  ; CHECK-PIC: ldr  x0, {{\[}}[[REG]], :got_lo12:func]
+  ; CHECK-PIC: ret
+
   ret void ()* @func
 }
 
Index: compiler-rt/test/hwasan/TestCases/exported-tagged-global.c
===
--- /dev/null
+++ compiler-rt/test/hwasan/TestCases/exported-tagged-global.c
@@ -0,0 +1,16 @@
+// RUN: %clang_hwasan %s -o %t
+// RUN: %run %t
+// RUN: %clang_hwasan -O1 %s -o %t
+// RUN: %run %t
+
+static int global;
+
+__attribute__((optnone)) int* address_of_global() {
+  return &global;
+}
+
+int main(int argc, char **argv) {
+  int* global_address = address_of_global();
+  *global_address = 13;
+  return 0;
+}
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -869,8 +869,12 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=hwaddress -fsanitize-hwaddress-abi=foo %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HWASAN-FOO-ABI
 // CHECK-HWASAN-INTERCEPTOR-ABI: "-default-function-attr" "hwasan-abi=interceptor"
 // CHECK-HWASAN-INTERCEPTOR-ABI: "-target-feature" "+tagged-globals"
+// CHECK-HWASAN-INTERCEPTOR-ABI: "-mllvm" "--aarch64-enable-global-isel-at-O=-1"
+// CHECK-HWASAN-INTERCEPTOR-ABI: "-mllvm" "-fast-isel=false"
 // CHECK-HWASAN-PLATFORM-ABI: "-default-function-attr" "hwasan-abi=platform"
 // CHECK-HWASAN-PLATFORM-ABI: "-target-feature" "+tagged-globals"
+// CHECK-HWASAN-PLATFORM-ABI: "-mllvm" "--aarch64-enable-global-isel-at-O=-1"
+// CHECK-HWASAN-PLATFORM

[PATCH] D82249: [HWASan] Disable GlobalISel/FastISel for HWASan Globals.

2020-06-22 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D82249#2105036 , @arsenm wrote:

> Is the fallback not working correctly in this case for some reason?


I'm fairly sure that G_GLOBAL_VALUE used to fallback onto SelectionDAGISel, and 
that was changed in D78465 . Because we only 
implemented the custom `adrp+movk` lowering in SelectionDAGISel, making that 
instruction sequence no longer fallback, so we don't get our proper lowering 
for HWASan globals.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82249



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


[PATCH] D82249: [HWASan] Disable GlobalISel/FastISel for HWASan Globals.

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

In D82249#2109920 , @eugenis wrote:

> I'm OK with this as a workaround, but it would be more natural to detect the 
> unsupported IR pattern in globalisel and fall back instead of disabling it 
> entirely. Is it difficult to do for some reason?


Eh, it's not an unsupported IR pattern that's the problem, it's that the IR is 
lowered into `adrp + add` so that the `add` can be folded into a `ldr/str` as 
an offset. IMO on the scale of "painting over the problem vs. fixing it", this 
patch is 100% paint, forced fallback with `MO_TAGGED` is 80% paint for maybe 
60% of the work of just fixing it.

I'm working on fixing this properly now that we know we don't need to make a 
less-risky, fast-to-deploy patch. If that all falls into place this patchset 
will just become obsolete anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82249



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


[PATCH] D82249: [HWASan] Disable GlobalISel/FastISel for HWASan Globals.

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

In D82249#2110010 , @arsenm wrote:

> I don't follow. It no longer falls back, so what is the problem?


HWASan-globals end up with an address that's outside of the code model (due to 
the tag), so the normal instruction sequence of `adrp + mov` or `adrp + ldr/str 
(with folded imm)` isn't adequate. In SelectionDAGISel, we emit a `movk` as 
well after the `adrp` to capture the top 16 bits. We need to do the same for 
GlobalISel. This is a temporary workaround to fix HWASan at `-O0` while I go 
and add support for adding the tagged-address lowering in GlobalISel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82249



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


[PATCH] D82249: [HWASan] Disable GlobalISel/FastISel for HWASan Globals.

2020-06-25 Thread Mitch Phillips via Phabricator via cfe-commits
hctim abandoned this revision.
hctim added a comment.

Abandoning - fixing the underlying issue at D82615 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82249



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


[PATCH] D82926: [libfuzzer] [clang] Add __has_feature(fuzzing_coverage)

2020-06-30 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added reviewers: morehouse, Dor1s.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Probably a useful feature for checking whether a file was built with
-fsanitize=fuzzer or -fsanitize=fuzzer-no-link.

N.B. __has_feature(fuzzing_coverage) doesn't cover instances where users
manually specify -fsanitize-coverage=... (even if the flags are
identical to ToT -fsanitize=fuzzer-no-link). IMHO this is WAI -
-fsanitize=fuzzer-no-link is not a stable set of flags and people that
want sancov for fuzzing should use fuzzer-no-link.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82926

Files:
  clang/include/clang/Basic/Features.def
  clang/test/Lexer/has_feature_libfuzzer.cpp


Index: clang/test/Lexer/has_feature_libfuzzer.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_libfuzzer.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer-no-link %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+
+#if __has_feature(fuzzing_coverage)
+int FuzzingCoverageEnabled();
+#else
+int FuzzingCoverageDisabled();
+#endif
+
+// CHECK-NONE: FuzzingCoverageEnabled
+// CHECK-ENABLED: FuzzingCoverageDisabled
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -49,6 +49,9 @@
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(fuzzing_coverage,
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Fuzzer |
+   SanitizerKind::FuzzerNoLink))
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
 FEATURE(attribute_availability, true)


Index: clang/test/Lexer/has_feature_libfuzzer.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_libfuzzer.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer-no-link %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+
+#if __has_feature(fuzzing_coverage)
+int FuzzingCoverageEnabled();
+#else
+int FuzzingCoverageDisabled();
+#endif
+
+// CHECK-NONE: FuzzingCoverageEnabled
+// CHECK-ENABLED: FuzzingCoverageDisabled
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -49,6 +49,9 @@
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(fuzzing_coverage,
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Fuzzer |
+   SanitizerKind::FuzzerNoLink))
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
 FEATURE(attribute_availability, true)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82926: [libfuzzer] [clang] Add __has_feature(fuzzing_coverage)

2020-06-30 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 274656.
hctim added a comment.

Changed the filename and fixed up the inverted test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82926

Files:
  clang/include/clang/Basic/Features.def
  clang/test/Lexer/has_feature_fuzzing_coverage.cpp


Index: clang/test/Lexer/has_feature_fuzzing_coverage.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_fuzzing_coverage.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer-no-link %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+
+#if __has_feature(fuzzing_coverage)
+int FuzzingCoverageEnabled();
+#else
+int FuzzingCoverageDisabled();
+#endif
+
+// CHECK-NONE: FuzzingCoverageDisabled
+// CHECK-ENABLED: FuzzingCoverageEnabled
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -49,6 +49,9 @@
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(fuzzing_coverage,
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Fuzzer |
+   SanitizerKind::FuzzerNoLink))
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
 FEATURE(attribute_availability, true)


Index: clang/test/Lexer/has_feature_fuzzing_coverage.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_fuzzing_coverage.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer-no-link %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-ENABLED %s
+
+#if __has_feature(fuzzing_coverage)
+int FuzzingCoverageEnabled();
+#else
+int FuzzingCoverageDisabled();
+#endif
+
+// CHECK-NONE: FuzzingCoverageDisabled
+// CHECK-ENABLED: FuzzingCoverageEnabled
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -49,6 +49,9 @@
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(fuzzing_coverage,
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Fuzzer |
+   SanitizerKind::FuzzerNoLink))
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
 FEATURE(attribute_availability, true)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84572: Allow .dSYM's to be directly placed in an alternate directory

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

Hi folks, looks like this patch broke `check-clang` under ASan/MSan, would you 
mind taking a look? Thanks.

  FAIL: Clang :: Driver/darwin-dsymutil.c (6208 of 24675)
   TEST 'Clang :: Driver/darwin-dsymutil.c' FAILED 

  Script:
  --
  : 'RUN: at line 3';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -target 
x86_64-apple-darwin10 -ccc-print-phases-arch i386 -arch x86_64 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
 -g 2> 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
  : 'RUN: at line 5';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck 
-check-prefix=CHECK-MULTIARCH-ACTIONS < 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
  : 'RUN: at line 18';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -target 
x86_64-apple-darwin10 -ccc-print-bindings-arch i386 -arch x86_64 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
 -g 2> 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
  : 'RUN: at line 20';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck 
-check-prefix=CHECK-MULTIARCH-BINDINGS < 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
  : 'RUN: at line 27';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -target 
x86_64-apple-darwin10 -ccc-print-bindings-o foo 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
 -g 2> 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
  : 'RUN: at line 29';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck 
-Doutfile=foo -Ddsymfile=foo.dSYM   -check-prefix=CHECK-OUTPUT-NAME < 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
  : 'RUN: at line 32';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -target 
x86_64-apple-darwin10 -ccc-print-bindings-o bar/foo 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
 -g 2> 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
  : 'RUN: at line 34';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck 
-Doutfile=bar/foo -Ddsymfile=bar/foo.dSYM
-check-prefix=CHECK-OUTPUT-NAME < 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
  : 'RUN: at line 37';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -target 
x86_64-apple-darwin10 -ccc-print-bindings-o bar/foo -dsym-dir external 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
 -g 2> 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
  : 'RUN: at line 39';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck 
-Doutfile=bar/foo -Ddsymfile=external/foo.dSYM
-check-prefix=CHECK-OUTPUT-NAME < 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
  : 'RUN: at line 47';   touch 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp.o
  : 'RUN: at line 48';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -target 
x86_64-apple-darwin10 -ccc-print-bindings-o foo 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp.o
 -g 2> 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
  : 'RUN: at line 50';   not grep "Dsymutil" 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/tools/clang/test/Driver/Output/darwin-dsymutil.c.tmp
  : 'RUN: at line 53';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -m32 -arch 
x86_64 -g 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Driver/darwin-dsymutil.c
 -###
  --
  Exit Code: 1

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/44506


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84572

[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] 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] 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-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 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: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] 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] 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-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] 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-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] 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] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-04-01 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 7 inline comments as done.
hctim added inline comments.
Herald added a subscriber: StephenFan.



Comment at: clang/test/Lexer/has_feature_memtag_stack.cpp:2
+// RUN: %clang_cc1 -E -fsanitize=memtag-stack %s -o - | FileCheck 
--check-prefix=CHECK-MEMTAG %s
+// RUN: %clang -E -fsanitize=memtag --target=aarch64-unknown-linux 
-march=armv8a+memtag %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-MEMTAG %s

MaskRay wrote:
> `%clang` is generally only used in test/Driver tests. (There are violations 
> but the patch should not add more).
It looks like the SanitizerGroups aren't parsed in in the cc1 invocation, given 
that using `-cc1` provides an error of:

`error: invalid value 'memtag' in '-fsanitize='`

non-cc1 invocations are thus standard (see 
`clang/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp` for an example) 
for testing sanitizers.

(fwiw - I couldn't find out *why* there's a discrepancy between sanitizers and 
sanitizer groups, otherwise we could potentially fix it, but it would only be 
for the sake of "making tests all use _cc1")


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

(comments)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp

Index: clang/test/Lexer/has_feature_memtag_sanitizer.cpp
===
--- clang/test/Lexer/has_feature_memtag_sanitizer.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fsanitize=memtag %s -o - | FileCheck --check-prefix=CHECK-MEMTAG %s
-// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
-
-#if __has_feature(memtag_sanitizer)
-int MemTagSanitizerEnabled();
-#else
-int MemTagSanitizerDisabled();
-#endif
-
-// CHECK-MEMTAG: MemTagSanitizerEnabled
-// CHECK-NO-MEMTAG: MemTagSanitizerDisabled
Index: clang/test/Lexer/has_feature_memtag.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_memtag.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -E -fsanitize=memtag-stack %s -o - | FileCheck --check-prefix=CHECK-MEMTAG-STACK %s
+// RUN: %clang_cc1 -E -fsanitize=memtag-heap %s -o -  | FileCheck --check-prefix=CHECK-MEMTAG-HEAP %s
+// RUN: %clang -E -fsanitize=memtag --target=aarch64-unknown-linux -march=armv8a+memtag %s -o - \
+// RUN: | FileCheck --check-prefixes=CHECK-MEMTAG-STACK,CHECK-MEMTAG-HEAP %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
+
+#if __has_feature(memtag_stack)
+int MemTagSanitizerStack();
+#else
+int MemTagSanitizerNoStack();
+#endif
+
+#if __has_feature(memtag_heap)
+int MemTagSanitizerHeap();
+#else
+int MemTagSanitizerNoHeap();
+#endif
+
+// CHECK-MEMTAG-STACK: MemTagSanitizerStack
+// CHECK-MEMTAG-HEAP: MemTagSanitizerHeap
+
+// CHECK-NO-MEMTAG: MemTagSanitizerNoStack
+// CHECK-NO-MEMTAG: MemTagSanitizerNoHeap
Index: clang/test/Driver/memtag.c
===
--- /dev/null
+++ clang/test/Driver/memtag.c
@@ -1,20 +0,0 @@
-// RUN: %clang -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SAFETY
-// RUN: %clang -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O2 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O3 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-
-// REQUIRES: aarch64-registered-target
-
-int z;
-__attribute__((noinline)) void use(int *p) { *p = z; }
-int foo() {
-  int x;
-  use(&x);
-  return x;
-}
-
-// CHECK-NO-SAFETY-NOT: allocas uses
-
-// CHECK-SAFETY-LABEL: @foo
-// CHECK-SAFETY-LABEL: allocas uses:
-// CHECK-SAFETY-NEXT: [4]: [0,4)
Index: clang/test/Driver/memtag-ld.c
===
--- /dev/null
+++ clang/test/Driver/memtag-ld.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-HEAP,CHECK-STACK,CHECK-DEFAULT-MODE
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-NO-HEAP,CHECK-STACK,CHECK-DEFAULT-MODE
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-HEAP,CHECK-NO-STACK,CHECK-DEFAULT-MODE
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag -fsanitize-memtag-mode=sync %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-DEFAULT-MODE,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack -fsanitize-memtag-mode=sync %s 2>&1 \
+// RUN:   | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-DEFAULT-MODE,CHECK-NO

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

(comments)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp

Index: clang/test/Lexer/has_feature_memtag_sanitizer.cpp
===
--- clang/test/Lexer/has_feature_memtag_sanitizer.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fsanitize=memtag %s -o - | FileCheck --check-prefix=CHECK-MEMTAG %s
-// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
-
-#if __has_feature(memtag_sanitizer)
-int MemTagSanitizerEnabled();
-#else
-int MemTagSanitizerDisabled();
-#endif
-
-// CHECK-MEMTAG: MemTagSanitizerEnabled
-// CHECK-NO-MEMTAG: MemTagSanitizerDisabled
Index: clang/test/Lexer/has_feature_memtag.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_memtag.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -E -fsanitize=memtag-stack %s -o - | FileCheck --check-prefix=CHECK-MEMTAG-STACK %s
+// RUN: %clang_cc1 -E -fsanitize=memtag-heap %s -o -  | FileCheck --check-prefix=CHECK-MEMTAG-HEAP %s
+// RUN: %clang -E -fsanitize=memtag --target=aarch64-unknown-linux -march=armv8a+memtag %s -o - \
+// RUN: | FileCheck --check-prefixes=CHECK-MEMTAG-STACK,CHECK-MEMTAG-HEAP %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
+
+#if __has_feature(memtag_stack)
+int MemTagSanitizerStack();
+#else
+int MemTagSanitizerNoStack();
+#endif
+
+#if __has_feature(memtag_heap)
+int MemTagSanitizerHeap();
+#else
+int MemTagSanitizerNoHeap();
+#endif
+
+// CHECK-MEMTAG-STACK: MemTagSanitizerStack
+// CHECK-MEMTAG-HEAP: MemTagSanitizerHeap
+
+// CHECK-NO-MEMTAG: MemTagSanitizerNoStack
+// CHECK-NO-MEMTAG: MemTagSanitizerNoHeap
Index: clang/test/Driver/memtag.c
===
--- /dev/null
+++ clang/test/Driver/memtag.c
@@ -1,20 +0,0 @@
-// RUN: %clang -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SAFETY
-// RUN: %clang -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O2 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O3 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-
-// REQUIRES: aarch64-registered-target
-
-int z;
-__attribute__((noinline)) void use(int *p) { *p = z; }
-int foo() {
-  int x;
-  use(&x);
-  return x;
-}
-
-// CHECK-NO-SAFETY-NOT: allocas uses
-
-// CHECK-SAFETY-LABEL: @foo
-// CHECK-SAFETY-LABEL: allocas uses:
-// CHECK-SAFETY-NEXT: [4]: [0,4)
Index: clang/test/Driver/memtag-ld.c
===
--- /dev/null
+++ clang/test/Driver/memtag-ld.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-NO-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag -fsanitize-memtag-mode=async %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack -fsanitize-memtag-mode=async %s 2>&1 \
+// RUN:   | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang 

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-04-04 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked an inline comment as done.
hctim added inline comments.



Comment at: clang/test/Driver/memtag-ld.c:36
+
+// CHECK-ASYNC: ld{{.*}} "-memtag-mode=async"
+// CHECK-DEFAULT-MODE-NOT: ld{{.*}} "--android-memtag-mode=

MaskRay wrote:
> This will be easier to read if you make the strings after `:` aligned.
> 
> Is `-memtag-mode=async` `--android-memtag-mode=async` now?
thanks for the catch



Comment at: clang/test/Driver/memtag-ld.c:38
+// CHECK-DEFAULT-MODE-NOT: ld{{.*}} "--android-memtag-mode=
+// CHECK-HEAP: "--android-memtag-heap"
+// CHECK-NO-HEAP-NOT: "--android-memtag-heap"

MaskRay wrote:
> Prefer `CHECK-HEAP-SAME` to `CHECK-HEAP` whenever feasible.
There's no other CHECK-HEAP before this, so `-SAME` not possible


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

In D118948#3427344 , @tschuett wrote:

> Is `-fsanitize=memtag-heap` Android specific or target independent? It passes 
> Android flags to the linker?!?

The frontend flag should be target-independent. The clang driver knows to only 
pass Android flags to the linker where `TC.getTriple().isAndroid()` is true. 
This should allow a glibc-based implementation to live under the same 
`-fsanitize=memtag-heap` flag, just chainging the implementation based on the 
target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-04-05 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 420590.
hctim added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp

Index: clang/test/Lexer/has_feature_memtag_sanitizer.cpp
===
--- clang/test/Lexer/has_feature_memtag_sanitizer.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fsanitize=memtag %s -o - | FileCheck --check-prefix=CHECK-MEMTAG %s
-// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
-
-#if __has_feature(memtag_sanitizer)
-int MemTagSanitizerEnabled();
-#else
-int MemTagSanitizerDisabled();
-#endif
-
-// CHECK-MEMTAG: MemTagSanitizerEnabled
-// CHECK-NO-MEMTAG: MemTagSanitizerDisabled
Index: clang/test/Lexer/has_feature_memtag.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_memtag.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -E -fsanitize=memtag-stack %s -o - | FileCheck --check-prefix=CHECK-MEMTAG-STACK %s
+// RUN: %clang_cc1 -E -fsanitize=memtag-heap %s -o -  | FileCheck --check-prefix=CHECK-MEMTAG-HEAP %s
+// RUN: %clang -E -fsanitize=memtag --target=aarch64-unknown-linux -march=armv8a+memtag %s -o - \
+// RUN: | FileCheck --check-prefixes=CHECK-MEMTAG-STACK,CHECK-MEMTAG-HEAP %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
+
+#if __has_feature(memtag_stack)
+int MemTagSanitizerStack();
+#else
+int MemTagSanitizerNoStack();
+#endif
+
+#if __has_feature(memtag_heap)
+int MemTagSanitizerHeap();
+#else
+int MemTagSanitizerNoHeap();
+#endif
+
+// CHECK-MEMTAG-STACK: MemTagSanitizerStack
+// CHECK-MEMTAG-HEAP: MemTagSanitizerHeap
+
+// CHECK-NO-MEMTAG: MemTagSanitizerNoStack
+// CHECK-NO-MEMTAG: MemTagSanitizerNoHeap
Index: clang/test/Driver/memtag.c
===
--- /dev/null
+++ clang/test/Driver/memtag.c
@@ -1,20 +0,0 @@
-// RUN: %clang -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SAFETY
-// RUN: %clang -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O2 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O3 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-
-// REQUIRES: aarch64-registered-target
-
-int z;
-__attribute__((noinline)) void use(int *p) { *p = z; }
-int foo() {
-  int x;
-  use(&x);
-  return x;
-}
-
-// CHECK-NO-SAFETY-NOT: allocas uses
-
-// CHECK-SAFETY-LABEL: @foo
-// CHECK-SAFETY-LABEL: allocas uses:
-// CHECK-SAFETY-NEXT: [4]: [0,4)
Index: clang/test/Driver/memtag-ld.c
===
--- /dev/null
+++ clang/test/Driver/memtag-ld.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-NO-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag -fsanitize-memtag-mode=async %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack -fsanitize-memtag-mode=async %s 2>&1 \
+// RUN:   | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-04-05 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D118948#3428157 , @MaskRay wrote:

> Since this driver option has no-op for glibc/musl/other ELF OS, by convention 
> it should report an `err_drv_unsupported_opt_for_target` error.
> This allows configure-time detection.

Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-04-08 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 421581.
hctim added a comment.

Comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp

Index: clang/test/Lexer/has_feature_memtag_sanitizer.cpp
===
--- clang/test/Lexer/has_feature_memtag_sanitizer.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fsanitize=memtag %s -o - | FileCheck --check-prefix=CHECK-MEMTAG %s
-// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
-
-#if __has_feature(memtag_sanitizer)
-int MemTagSanitizerEnabled();
-#else
-int MemTagSanitizerDisabled();
-#endif
-
-// CHECK-MEMTAG: MemTagSanitizerEnabled
-// CHECK-NO-MEMTAG: MemTagSanitizerDisabled
Index: clang/test/Lexer/has_feature_memtag.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_memtag.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -E -fsanitize=memtag-stack %s -o - | FileCheck --check-prefix=CHECK-MEMTAG-STACK %s
+// RUN: %clang_cc1 -E -fsanitize=memtag-heap %s -o -  | FileCheck --check-prefix=CHECK-MEMTAG-HEAP %s
+// RUN: %clang -E -fsanitize=memtag --target=aarch64-unknown-linux -march=armv8a+memtag %s -o - \
+// RUN: | FileCheck --check-prefixes=CHECK-MEMTAG-STACK,CHECK-MEMTAG-HEAP %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
+
+#if __has_feature(memtag_stack)
+int MemTagSanitizerStack();
+#else
+int MemTagSanitizerNoStack();
+#endif
+
+#if __has_feature(memtag_heap)
+int MemTagSanitizerHeap();
+#else
+int MemTagSanitizerNoHeap();
+#endif
+
+// CHECK-MEMTAG-STACK: MemTagSanitizerStack
+// CHECK-MEMTAG-HEAP: MemTagSanitizerHeap
+
+// CHECK-NO-MEMTAG: MemTagSanitizerNoStack
+// CHECK-NO-MEMTAG: MemTagSanitizerNoHeap
Index: clang/test/Driver/memtag.c
===
--- /dev/null
+++ clang/test/Driver/memtag.c
@@ -1,20 +0,0 @@
-// RUN: %clang -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SAFETY
-// RUN: %clang -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O2 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O3 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-
-// REQUIRES: aarch64-registered-target
-
-int z;
-__attribute__((noinline)) void use(int *p) { *p = z; }
-int foo() {
-  int x;
-  use(&x);
-  return x;
-}
-
-// CHECK-NO-SAFETY-NOT: allocas uses
-
-// CHECK-SAFETY-LABEL: @foo
-// CHECK-SAFETY-LABEL: allocas uses:
-// CHECK-SAFETY-NEXT: [4]: [0,4)
Index: clang/test/Driver/memtag-ld.c
===
--- /dev/null
+++ clang/test/Driver/memtag-ld.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-NO-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag -fsanitize-memtag-mode=async %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack -fsanitize-memtag-mode=async %s 2>&1 \
+// RUN:   | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

Over to @eugenis for any final touches


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp

Index: clang/test/Lexer/has_feature_memtag_sanitizer.cpp
===
--- clang/test/Lexer/has_feature_memtag_sanitizer.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fsanitize=memtag %s -o - | FileCheck --check-prefix=CHECK-MEMTAG %s
-// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
-
-#if __has_feature(memtag_sanitizer)
-int MemTagSanitizerEnabled();
-#else
-int MemTagSanitizerDisabled();
-#endif
-
-// CHECK-MEMTAG: MemTagSanitizerEnabled
-// CHECK-NO-MEMTAG: MemTagSanitizerDisabled
Index: clang/test/Lexer/has_feature_memtag.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_memtag.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -E -fsanitize=memtag-stack %s -o - | FileCheck --check-prefix=CHECK-MEMTAG-STACK %s
+// RUN: %clang_cc1 -E -fsanitize=memtag-heap %s -o -  | FileCheck --check-prefix=CHECK-MEMTAG-HEAP %s
+// RUN: %clang -E -fsanitize=memtag --target=aarch64-unknown-linux -march=armv8a+memtag %s -o - \
+// RUN: | FileCheck --check-prefixes=CHECK-MEMTAG-STACK,CHECK-MEMTAG-HEAP %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
+
+#if __has_feature(memtag_stack)
+int MemTagSanitizerStack();
+#else
+int MemTagSanitizerNoStack();
+#endif
+
+#if __has_feature(memtag_heap)
+int MemTagSanitizerHeap();
+#else
+int MemTagSanitizerNoHeap();
+#endif
+
+// CHECK-MEMTAG-STACK: MemTagSanitizerStack
+// CHECK-MEMTAG-HEAP: MemTagSanitizerHeap
+
+// CHECK-NO-MEMTAG: MemTagSanitizerNoStack
+// CHECK-NO-MEMTAG: MemTagSanitizerNoHeap
Index: clang/test/Driver/memtag.c
===
--- /dev/null
+++ clang/test/Driver/memtag.c
@@ -1,20 +0,0 @@
-// RUN: %clang -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SAFETY
-// RUN: %clang -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O2 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-// RUN: %clang -O3 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print=1 %s -S -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SAFETY
-
-// REQUIRES: aarch64-registered-target
-
-int z;
-__attribute__((noinline)) void use(int *p) { *p = z; }
-int foo() {
-  int x;
-  use(&x);
-  return x;
-}
-
-// CHECK-NO-SAFETY-NOT: allocas uses
-
-// CHECK-SAFETY-LABEL: @foo
-// CHECK-SAFETY-LABEL: allocas uses:
-// CHECK-SAFETY-NEXT: [4]: [0,4)
Index: clang/test/Driver/memtag-ld.c
===
--- /dev/null
+++ clang/test/Driver/memtag-ld.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-NO-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag -fsanitize-memtag-mode=async %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack -fsanitize-memtag-mode=async %s 2>&1 \
+// RUN:   | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --tar

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-04-08 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:475
 def err_stack_tagging_requires_hardware_feature : Error<
-  "'-fsanitize=memtag' requires hardware support (+memtag)">;
+  "'-fsanitize=memtag-stack' requires hardware support (+memtag). For Armv8, "
+  "try compiling with -march=armv8a+memtag.">;

eugenis wrote:
> MaskRay wrote:
> > hctim wrote:
> > > eugenis wrote:
> > > > Split out renaming of memtag to memtag-stack first? This will remove a 
> > > > lot of diff from this patch.
> > > splitting into elf -> lld -> clang as per Ray's suggestion, should reduce 
> > > the diff enough.
> > The convention is to omit period for the last sentence.
> Mention armv9a, too?
> Something like "Try compiling with -march=armv9a, or -march=armv8a+memtag"
mentioned it similar to armv8, as mentioned we're not 100% clear whether MTE is 
mandatory on armv9.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-04-08 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 rG8aa1490513f1: [MTE] Add -fsanitize=memtag* and friends. 
(authored by hctim).

Changed prior to commit:
  https://reviews.llvm.org/D118948?vs=421593&id=421612#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp

Index: clang/test/Lexer/has_feature_memtag_sanitizer.cpp
===
--- clang/test/Lexer/has_feature_memtag_sanitizer.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fsanitize=memtag %s -o - | FileCheck --check-prefix=CHECK-MEMTAG %s
-// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
-
-#if __has_feature(memtag_sanitizer)
-int MemTagSanitizerEnabled();
-#else
-int MemTagSanitizerDisabled();
-#endif
-
-// CHECK-MEMTAG: MemTagSanitizerEnabled
-// CHECK-NO-MEMTAG: MemTagSanitizerDisabled
Index: clang/test/Lexer/has_feature_memtag.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_memtag.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -E -fsanitize=memtag-stack %s -o - | FileCheck --check-prefix=CHECK-MEMTAG-STACK %s
+// RUN: %clang_cc1 -E -fsanitize=memtag-heap %s -o -  | FileCheck --check-prefix=CHECK-MEMTAG-HEAP %s
+// RUN: %clang -E -fsanitize=memtag --target=aarch64-unknown-linux -march=armv8a+memtag %s -o - \
+// RUN: | FileCheck --check-prefixes=CHECK-MEMTAG-STACK,CHECK-MEMTAG-HEAP %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-MEMTAG %s
+
+#if __has_feature(memtag_stack)
+int MemTagSanitizerStack();
+#else
+int MemTagSanitizerNoStack();
+#endif
+
+#if __has_feature(memtag_heap)
+int MemTagSanitizerHeap();
+#else
+int MemTagSanitizerNoHeap();
+#endif
+
+// CHECK-MEMTAG-STACK: MemTagSanitizerStack
+// CHECK-MEMTAG-HEAP: MemTagSanitizerHeap
+
+// CHECK-NO-MEMTAG: MemTagSanitizerNoStack
+// CHECK-NO-MEMTAG: MemTagSanitizerNoHeap
Index: clang/test/Driver/memtag-ld.c
===
--- /dev/null
+++ clang/test/Driver/memtag-ld.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-SYNC,CHECK-HEAP,CHECK-NO-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag -fsanitize-memtag-mode=async %s 2>&1 | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack -fsanitize-memtag-mode=async %s 2>&1 \
+// RUN:   | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-NO-HEAP,CHECK-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap -fsanitize-memtag-mode=async %s 2>&1 \
+// RUN:   | FileCheck %s \
+// RUN:   --check-prefixes=CHECK-ASYNC,CHECK-HEAP,CHECK-NO-STACK
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-heap -fsanitize-memtag-mode=asymm %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefixes=CHECK-INVALID-MODE
+
+// RUN: %clang -### --target=aarch64-linux-android -march=armv8+memtag \
+// RUN:   -fsanitize=memtag-stack -fsanitize=memtag-heap \
+// RUN:   -fsanitize-memtag-mode=asymm -fno-sanitize=memtag %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefixes=CHECK-NONE
+
+// CHECK-ASYNC: ld{{.*}} "--android-memtag-mode=async"
+// CHECK-SYNC:  ld{{.*}} "--android-memtag-mode=sync"
+// CHECK-HEAP:  "--android-memtag-heap"
+// CHECK-NO-HEAP-NOT:   "--android-memtag-heap"
+// CHECK-STACK: "--android-me

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

Thanks, I'll take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-11 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added reviewers: echristo, cmtice.
Herald added a project: All.
hctim requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

An upcoming patch will extend llvm-symbolizer to provide the source line
information for global variables. The goal is to move AddressSanitizer
off of internal debug info for symbolization onto the DWARF standard
(and doing a clean-up in the process). Currently, ASan reports the line
information for constant strings if a memory safety bug happens around
them. We want to keep this behaviour, so we need to emit debuginfo for
these variables as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123534

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/debug-info-variables.c
  clang/test/VFS/external-names.c

Index: clang/test/VFS/external-names.c
===
--- clang/test/VFS/external-names.c
+++ clang/test/VFS/external-names.c
@@ -30,8 +30,8 @@
 // Debug info
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG-EXTERNAL %s
-// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num:[0-9]+]]
-// CHECK-DEBUG-EXTERNAL: ![[Num]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: ![[Num:[0-9]+]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num]]
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG %s
 // CHECK-DEBUG-NOT: Inputs
Index: clang/test/CodeGen/debug-info-variables.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-variables.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -debug-info-kind=standalone -S -emit-llvm -o - | FileCheck %s
+
+// CHECK: DIGlobalVariable(name: "global"
+int global = 42;
+
+// CHECK: DIGlobalVariable({{.*}}line: [[@LINE+2]]
+const char* s() {
+  return "1234567890";
+}
+
+// CHECK: DILocalVariable(name: "p"
+// CHECK: DILocalVariable(name: "q"
+// CHECK: DILocalVariable(name: "r"
+int sum(int p, int q) {
+  int r = p + q;
+  return r;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5624,6 +5624,12 @@
   }
 
   auto GV = GenerateStringLiteral(C, LT, *this, GlobalVariableName, Alignment);
+
+  CGDebugInfo *DI = getModuleDebugInfo();
+  if (DI && getCodeGenOpts().hasReducedDebugInfo())
+DI->AddStringLiteralDebugInfo(GV, GlobalVariableName, S->getStrTokenLoc(0),
+  S->getByteLength());
+
   if (Entry)
 *Entry = GV;
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -533,6 +533,10 @@
   /// Emit an @import declaration.
   void EmitImportDecl(const ImportDecl &ID);
 
+  /// Create and attach debuginfo to a the provided string literal GV.
+  void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV, StringRef Name,
+ const SourceLocation &Loc, unsigned Length);
+
   /// Emit C++ namespace alias.
   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5118,7 +5118,7 @@
 return Name;
   codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
   CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
-  
+
   if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
 TemplateNamesKind = codegenoptions::DebugTemplateNamesKind::Full;
 
@@ -5445,6 +5445,21 @@
   ImportedDeclCache[GD.getCanonicalDecl().getDecl()].reset(ImportDI);
 }
 
+void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
+StringRef Name,
+const SourceLocation &Loc,
+unsigned Length) {
+  PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
+  if (!PLoc.isValid())
+return;
+
+  llvm::DIGlobalVariableExpression *Debug =
+  DBuilder.createGlobalVariableExpression(
+  nullptr, Name, Name, getOrCreateFile(Loc), getLineNumber(Loc),
+  DBuilder.createStringType(Name, Length), true);
+  GV->addDebugInfo(Debug);
+}
+
 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
   if (!LexicalBlockStack.empty())
 return Le

[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

In D123534#3454354 , @dblaikie wrote:

> This seems like it would significantly introduce debug info size for at least 
> some kinds of code - have you done any size measurements of this change?

With `-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=On`:

- Before the patch: `clang` was 1247264656 bytes
- After the patch: `clang` was 1270191696 bytes (or, a 1.84% increase)

> What does the resulting DWARF look like?

Each string DI ends up looking like a regular global variable (i.e. a 
`DW_TAG_variable` entry in `.debug_info`):

  $ llvm-dwarfdump --debug-info
  0x0032:   DW_TAG_variable
  DW_AT_name  (".str")
  DW_AT_type  (0x003e ".str")
  DW_AT_decl_file ("/tmp/file.c")
  DW_AT_decl_line (3)
  DW_AT_location  (DW_OP_addrx 0x1)
  DW_AT_linkage_name  (".str")

(and obviously an entry in the `.debug_addr` referenced by the `DW_AT_location` 
at index `0x1`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

  section : increase in bytes for clang built with full debuginfo : %% of total 
binary size
  .debug_loclists   317782  0.0250%
  .debug_abbrev 88590   0.0070%
  .debug_info   100708340.7929%
  .debug_rnglists   143320  0.0113%
  .debug_str_offsets1090516 0.0859%
  .debug_str7789440 0.6132%
  .debug_addr   3611552 0.2843%
  .debug_line   -187964 -0.0148%
  .debug_line_str   20430.0002%


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

In D123534#3462551 , @dblaikie wrote:

> What's the DW_AT_type referring to? (why is there a type called ".str"?)
>
> For your particular purposes, it seems like the name/type/linkage name could 
> all be omitted & that might be OK, since these entities aren't actually named 
> in the source?



In D123534#3462849 , @probinson wrote:

> I'd expect it to point to a base type, in this case character string.  A 
> typeless variable with a location would be pretty weird.
> But I agree the name/linkage_name would be unnecessary.

I've updated the patch to:

1. Omit the linkage name,
2. Omit the display name (including associated changes to allow this), and
3. Used the `char[SIZE]` type.

#3 could be optimised for file size further by changing to a `const char*` 
type, but I:

1. Can't see an obvious way to synthesize a `const char*` `QualType` to pass to 
`createGlobalVariableExpression`, and
2. Think it might actually be useful to have the correct type here (as it now 
also describes the size of the variable).

Here's the new dwarfdump:

  0x0065:   DW_TAG_variable 
  
  DW_AT_type  (0x006f "char [11]")  
  
  DW_AT_decl_file ("/tmp/file.c")   
  
  DW_AT_decl_line (4)   
  
  DW_AT_location  (DW_OP_addrx 0x3) 
  

  
  0x006f:   DW_TAG_array_type   
  
  DW_AT_type  (0x0048 "char")   
  

  
  0x0074: DW_TAG_subrange_type  
  
DW_AT_type(0x004c "__ARRAY_SIZE_TYPE__")
  
DW_AT_count   (0x0b)
  

  
  0x007a: NULL

Apparently with `-DCMAKE_BUILD_TYPE='RelWithDebInfo'`, `bin/clang-15` went from 
1373029152B to 1373030960B (~0%), which seems suspiciously low to me. I double 
checked the builds twice, and they seem to be right...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-20 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 424055.
hctim added a comment.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Patch update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/debug-info-variables.c
  clang/test/VFS/external-names.c
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -165,7 +165,9 @@
   } else {
 DeclContext = GV->getScope();
 // Add name and type.
-addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
+StringRef DisplayName = GV->getDisplayName();
+if (!DisplayName.empty())
+  addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
 if (GTy)
   addType(*VariableDIE, GTy);
 
Index: clang/test/VFS/external-names.c
===
--- clang/test/VFS/external-names.c
+++ clang/test/VFS/external-names.c
@@ -30,8 +30,8 @@
 // Debug info
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG-EXTERNAL %s
-// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num:[0-9]+]]
-// CHECK-DEBUG-EXTERNAL: ![[Num]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: ![[Num:[0-9]+]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num]]
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG %s
 // CHECK-DEBUG-NOT: Inputs
Index: clang/test/CodeGen/debug-info-variables.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-variables.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -debug-info-kind=standalone -S -emit-llvm -o - | FileCheck %s
+
+// CHECK: DIGlobalVariable(name: "global"
+int global = 42;
+
+// CHECK: DIGlobalVariable({{.*}}line: [[@LINE+2]]
+const char* s() {
+  return "1234567890";
+}
+
+// CHECK: DILocalVariable(name: "p"
+// CHECK: DILocalVariable(name: "q"
+// CHECK: DILocalVariable(name: "r"
+int sum(int p, int q) {
+  int r = p + q;
+  return r;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5660,6 +5660,11 @@
   }
 
   auto GV = GenerateStringLiteral(C, LT, *this, GlobalVariableName, Alignment);
+
+  CGDebugInfo *DI = getModuleDebugInfo();
+  if (DI && getCodeGenOpts().hasReducedDebugInfo())
+DI->AddStringLiteralDebugInfo(GV, GlobalVariableName, S);
+
   if (Entry)
 *Entry = GV;
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -533,6 +533,10 @@
   /// Emit an @import declaration.
   void EmitImportDecl(const ImportDecl &ID);
 
+  /// Create and attach debuginfo to a the provided string literal GV.
+  void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV, StringRef Name,
+ const StringLiteral *S);
+
   /// Emit C++ namespace alias.
   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5119,7 +5119,7 @@
 return Name;
   codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
   CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
-  
+
   if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
 TemplateNamesKind = codegenoptions::DebugTemplateNamesKind::Full;
 
@@ -5446,6 +5446,22 @@
   ImportedDeclCache[GD.getCanonicalDecl().getDecl()].reset(ImportDI);
 }
 
+void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
+StringRef Name,
+const StringLiteral *S) {
+  SourceLocation Loc = S->getStrTokenLoc(0);
+  PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
+  if (!PLoc.isValid())
+return;
+
+  llvm::DIFile *File = getOrCreateFile(Loc);
+  llvm::DIGlobalVariableExpression *Debug =
+  DBuilder.createGlobalVariableExpression(
+  nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
+  getLineNumber(Loc), getOrCreateType(S->getType(), File), tr

[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

Confirmed again with `-DCMAKE_BUILD_TYPE=RelWithDebInfo 
-DLLVM_ENABLE_ASSERTIONS=On`:

1510883864 (new) - 1510881800 (old) = 2064 bytes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

Yeah, as I drove away from my desk I realized my mistake. Will get new accurate 
numbers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

1263559896 (new) - 1248280328 (old) = 15279568 B (1.22% increase). Seems more 
reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

I just did an experiment with the following patch that punts everything to 
`const char*` types to try and get better folding onto a single type:

The change didn't make a significant difference, with the clang binary size of 
1263433512 (126384B reduction, or 1.224% -> 1.214%). I think it's better to 
keep the extra size diagnostic.

  diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
  index f82c0e357bc3..175a5fec2989 100644
  --- a/clang/lib/CodeGen/CGDebugInfo.cpp
  +++ b/clang/lib/CodeGen/CGDebugInfo.cpp
  @@ -5454,11 +5454,23 @@ void 
CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
 if (!PLoc.isValid())
   return;
   
  +  // Official type of the StringLiteral is `char[N]`. This means for each
  +  // compilation unit, we have multiple DW_*_type entries, one set for each 
size
  +  // of constant string. This level of precision isn't necessary, so simply
  +  // synthesize a `const char*` type so it can be reused across all constant
  +  // strings.
  +  const auto &Context = CGM.getContext();
  +  QualType Type = Context.CharTy;
  +  Type.addConst();
  +  Type = Context.getPointerType(Type);
  +
  +  // Similar to above, elide the name variables (as there isn't really 
anything
  +  // useful we can add) to save binary size.
 llvm::DIFile *File = getOrCreateFile(Loc);
 llvm::DIGlobalVariableExpression *Debug =
 DBuilder.createGlobalVariableExpression(
 nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
  -  getLineNumber(Loc), getOrCreateType(S->getType(), File), true);
  +  getLineNumber(Loc), getOrCreateType(Type, File), true);
 GV->addDebugInfo(Debug);
   }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-02-03 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: eugenis.
Herald added subscribers: dexonsmith, dang, arichardson, emaste.
Herald added a reviewer: MaskRay.
hctim requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Currently, enablement of heap MTE on Android is specified by an ELF note, which
signals to the linker to enable heap MTE. This change allows
-fsanitize=memtag-heap to synthesize these notes, rather than adding them
through the build system. We need to extend this feature to also signal the
linker to do special work for MTE globals (in future) and MTE stack (currently
implemented in the toolchain, but not implemented in the loader).

Current Android uses a non-backwards-compatible ELF note, called
".note.android.memtag". Stack MTE is an ABI break anyway, so we don't mind that
we won't be able to run executables with stack MTE on Android 11/12 devices.

The current expectation is to support the verbiage used by Android, in
that "SYNC" means MTE Synchronous mode, and "ASYNC" effectively means
"fast", using the Kernel auto-upgrade feature that allows
hardware-specific and core-specific configuration as to whether "ASYNC"
would end up being Asynchronous, Asymmetric, or Synchronous on that
particular core, whichever has a reasonable performance delta. Of
course, this is platform and loader-specific.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag_heap.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp
  clang/test/Lexer/has_feature_memtag_stack.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/ELF/SyntheticSections.cpp
  lld/ELF/SyntheticSections.h
  lld/ELF/Writer.cpp
  lld/test/ELF/memtag-android-abi.s
  llvm/include/llvm/BinaryFormat/ELF.h

Index: llvm/include/llvm/BinaryFormat/ELF.h
===
--- llvm/include/llvm/BinaryFormat/ELF.h
+++ llvm/include/llvm/BinaryFormat/ELF.h
@@ -1531,6 +1531,22 @@
   NT_GNU_PROPERTY_TYPE_0 = 5,
 };
 
+// Android note types.
+enum {
+  NT_TYPE_IDENT = 1,
+  NT_TYPE_KUSER = 3,
+  NT_TYPE_MEMTAG = 4,
+};
+
+enum {
+  NT_MEMTAG_LEVEL_DEFAULT = 0,
+  NT_MEMTAG_LEVEL_ASYNC = 1,
+  NT_MEMTAG_LEVEL_SYNC = 2,
+  NT_MEMTAG_LEVEL_MASK = 3,
+  NT_MEMTAG_HEAP = 4,
+  NT_MEMTAG_STACK = 8,
+};
+
 // Property types used in GNU_PROPERTY_TYPE_0 notes.
 enum : unsigned {
   GNU_PROPERTY_STACK_SIZE = 1,
Index: lld/test/ELF/memtag-android-abi.s
===
--- /dev/null
+++ lld/test/ELF/memtag-android-abi.s
@@ -0,0 +1,63 @@
+// Old versions of Android (Android 11 & 12) have very strict parsing logic on
+// the layout of the ELF note. This test serves as a "hey, you're going to break
+// the ABI" check. Basically below is the copied version of the Android parsing
+// logic. We create a no-op aarch64 binary with an elf note, and then consume it
+// using the parsing logic on the host system. Because we don't pull in any
+// libraries or headers, this should be runnable on any system that uses linux
+// (technically, any system that can parse ELF, but I'm not rewriting it in
+// python to run on Windows...). Note that MTE stack is an ABI break, so we
+// expect it to crash under this parsing logic.
+
+// RUN: llvm-mc --filetype=obj -triple=aarch64-linux-none-gnu %s -o %t.o
+// RUN: ld.lld --memtag-mode=async %t.o -o %t
+// RUN: llvm-readelf -S %t | FileCheck %s
+// RUN: llvm-objdump -Dz -j .note.android.memtag %t | \
+// RUN:FileCheck %s --check-prefixes=NOTE,ASYNC-NOTE
+
+// RUN: ld.lld --memtag-mode=sync %t.o -o %t
+// RUN: llvm-readelf -S %t | FileCheck %s
+// RUN: llvm-objdump -Dz -j .note.android.memtag %t | \
+// RUN:FileCheck %s --check-prefixes=NOTE,SYNC-NOTE
+
+// RUN: ld.lld --memtag-mode=async --memtag-stack %t.o -o %t
+// RUN: llvm-readelf -S %t | FileCheck %s
+// RUN: llvm-objdump -Dz -j .note.android.memtag %t | \
+// RUN:FileCheck %s --check-prefixes=NOTE,STACK-ASYNC
+
+// RUN: ld.lld --memtag-mode=sync --memtag-stack %t.o -o %t
+// RUN: llvm-readelf -S %t | FileCheck %s
+// RUN: llvm-objdump -Dz -j .note.android.memtag %t | \
+// RUN:FileCheck %s --check-prefixes=NOTE,STACK-SYNC
+
+// CHECK: .note.android.memtag
+
+// NOTE: <.note.android.memtag>:
+// NOTE-NEXT: : 08 00 00 00
+// NOTE-NEXT: : 04 00 00 00

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-02-03 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 9 inline comments as done.
hctim added inline comments.



Comment at: llvm/include/llvm/BinaryFormat/ELF.h:1536
+enum {
+  NT_TYPE_IDENT = 1,
+  NT_TYPE_KUSER = 3,

MaskRay wrote:
> If Android wants to define notes, can it use a namespace `NT_ANDROID_*` like 
> GNU?
> 
> Please see `https://reviews.llvm.org/D107949` how I add ELF attributes and 
> related tests when new additions are added to BinaryFormat/ELF.h
Android currently defines their internal note types in this naming scheme 
(https://cs.android.com/android/platform/superproject/+/master:bionic/libc/private/bionic_asm_note.h).

However, it seems like these are not used outside of Android internally, so let 
me slap some prefixes on them. Maybe I'll even get around to updating them in 
the Android tree as well, who knows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

Address Ray's comments, and made it so that stack MTE doesn't imply heap.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag_heap.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp
  clang/test/Lexer/has_feature_memtag_stack.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/ELF/SyntheticSections.cpp
  lld/ELF/SyntheticSections.h
  lld/ELF/Writer.cpp
  lld/test/ELF/aarch64-memtag-android-abi.s
  llvm/include/llvm/BinaryFormat/ELF.h

Index: llvm/include/llvm/BinaryFormat/ELF.h
===
--- llvm/include/llvm/BinaryFormat/ELF.h
+++ llvm/include/llvm/BinaryFormat/ELF.h
@@ -1531,6 +1531,22 @@
   NT_GNU_PROPERTY_TYPE_0 = 5,
 };
 
+// Android note types.
+enum {
+  NT_ANDROID_TYPE_IDENT = 1,
+  NT_ANDROID_TYPE_KUSER = 3,
+  NT_ANDROID_TYPE_MEMTAG = 4,
+};
+
+enum {
+  NT_MEMTAG_LEVEL_DEFAULT = 0,
+  NT_MEMTAG_LEVEL_ASYNC = 1,
+  NT_MEMTAG_LEVEL_SYNC = 2,
+  NT_MEMTAG_LEVEL_MASK = 3,
+  NT_MEMTAG_HEAP = 4,
+  NT_MEMTAG_STACK = 8,
+};
+
 // Property types used in GNU_PROPERTY_TYPE_0 notes.
 enum : unsigned {
   GNU_PROPERTY_STACK_SIZE = 1,
Index: lld/test/ELF/aarch64-memtag-android-abi.s
===
--- /dev/null
+++ lld/test/ELF/aarch64-memtag-android-abi.s
@@ -0,0 +1,78 @@
+# Old versions of Android (Android 11 & 12) have very strict parsing logic on
+# the layout of the ELF note. This test serves as a "hey, you're going to break
+# the ABI" check. Basically below is the copied version of the Android parsing
+# logic. We create a no-op aarch64 binary with an elf note, and then consume it
+# using the parsing logic on the host system. Because we don't pull in any
+# libraries or headers, this should be runnable on any system that uses linux
+# (technically, any system that can parse ELF, but I'm not rewriting it in
+# python to run on Windows...). Note that MTE stack is an ABI break, so we
+# expect it to crash under this parsing logic.
+
+# RUN: llvm-mc --filetype=obj -triple=aarch64-linux-none-gnu %s -o %t.o
+# RUN: ld.lld --memtag-mode=async --memtag-heap %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,HEAP-ASYNC-NOTE
+
+# RUN: ld.lld --memtag-mode=sync --memtag-heap %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,HEAP-SYNC-NOTE
+
+# RUN: ld.lld --memtag-mode=async --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,STACK-ASYNC
+
+# RUN: ld.lld --memtag-mode=sync --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,STACK-SYNC
+
+# RUN: ld.lld --memtag-mode=async --memtag-heap --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,BOTH-ASYNC
+
+# RUN: ld.lld --memtag-mode=sync --memtag-heap --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,BOTH-SYNC
+
+# NOTE: .note.android.memtag
+# NOTE-NEXT: Owner
+# TODO(hctim): Update llvm-readelf to understand this note type.
+# NOTE-NEXT: Android  0x0004  Unknown note type: (0x0004)
+
+# The next few lines are an ABI enforcement for Android 11 and 12. If you're
+# compiling with just heap MTE (i.e just --memtag-mode), then these lines MUST
+# be unchanging.
+# HEAP-ASYNC-NOTE-NEXT: description data: 05 00 00 00
+# HEAP-SYNC-NOTE-NEXT: description data: 06 00 00 00
+
+# Stack MTE is, as of Android 12, unimplemented. However, we pre-emptively emit
+# a bit that signifies to the dynamic loader to map the primary and thread
+# stacks as PROT_MTE, in preparation for the bionic support.
+# STACK-ASYNC-NEXT: description data: 09 00 00 00
+# STACK-SYNC-NEXT: description data: 0a 00 00 00
+
+# Stack MTE is, as of Android 12, unimplemented. However, we pre-emptively emit
+# a bit that signifies to the dynamic loader to map the primary and thread
+# stacks as PROT_MTE, in preparation for the bionic support.
+# BOTH-ASYNC-NEXT: description data: 0d 00 00 00
+# BOTH-SYNC-NEXT: description data: 0e 00 00 00
+
+# RUN: not ld.lld --memtag-stack 2>&1 | \
+# 

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

In D118948#3295321 , @MaskRay wrote:

> I haven't investigated the use case yet, just commented a few things. Please 
> split the patch into 3:
>
> - BinaryFormat/ELF.h (see an inline comment)
> - lld/ELF
> - clang

Can you clarify what you'd like (from D107949 
) in patch #1?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

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

(forgot to add REQUIRES: aarch64 to the lld test)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/Driver/fsanitize.c
  clang/test/Driver/memtag-ld.c
  clang/test/Driver/memtag-stack.c
  clang/test/Driver/memtag.c
  clang/test/Lexer/has_feature_memtag_heap.cpp
  clang/test/Lexer/has_feature_memtag_sanitizer.cpp
  clang/test/Lexer/has_feature_memtag_stack.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/ELF/SyntheticSections.cpp
  lld/ELF/SyntheticSections.h
  lld/ELF/Writer.cpp
  lld/test/ELF/aarch64-memtag-android-abi.s
  llvm/include/llvm/BinaryFormat/ELF.h

Index: llvm/include/llvm/BinaryFormat/ELF.h
===
--- llvm/include/llvm/BinaryFormat/ELF.h
+++ llvm/include/llvm/BinaryFormat/ELF.h
@@ -1531,6 +1531,22 @@
   NT_GNU_PROPERTY_TYPE_0 = 5,
 };
 
+// Android note types.
+enum {
+  NT_ANDROID_TYPE_IDENT = 1,
+  NT_ANDROID_TYPE_KUSER = 3,
+  NT_ANDROID_TYPE_MEMTAG = 4,
+};
+
+enum {
+  NT_MEMTAG_LEVEL_DEFAULT = 0,
+  NT_MEMTAG_LEVEL_ASYNC = 1,
+  NT_MEMTAG_LEVEL_SYNC = 2,
+  NT_MEMTAG_LEVEL_MASK = 3,
+  NT_MEMTAG_HEAP = 4,
+  NT_MEMTAG_STACK = 8,
+};
+
 // Property types used in GNU_PROPERTY_TYPE_0 notes.
 enum : unsigned {
   GNU_PROPERTY_STACK_SIZE = 1,
Index: lld/test/ELF/aarch64-memtag-android-abi.s
===
--- /dev/null
+++ lld/test/ELF/aarch64-memtag-android-abi.s
@@ -0,0 +1,80 @@
+# REQUIRES: aarch64
+
+# Old versions of Android (Android 11 & 12) have very strict parsing logic on
+# the layout of the ELF note. This test serves as a "hey, you're going to break
+# the ABI" check. Basically below is the copied version of the Android parsing
+# logic. We create a no-op aarch64 binary with an elf note, and then consume it
+# using the parsing logic on the host system. Because we don't pull in any
+# libraries or headers, this should be runnable on any system that uses linux
+# (technically, any system that can parse ELF, but I'm not rewriting it in
+# python to run on Windows...). Note that MTE stack is an ABI break, so we
+# expect it to crash under this parsing logic.
+
+# RUN: llvm-mc --filetype=obj -triple=aarch64-linux-none-gnu %s -o %t.o
+# RUN: ld.lld --memtag-mode=async --memtag-heap %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,HEAP-ASYNC-NOTE
+
+# RUN: ld.lld --memtag-mode=sync --memtag-heap %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,HEAP-SYNC-NOTE
+
+# RUN: ld.lld --memtag-mode=async --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,STACK-ASYNC
+
+# RUN: ld.lld --memtag-mode=sync --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,STACK-SYNC
+
+# RUN: ld.lld --memtag-mode=async --memtag-heap --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,BOTH-ASYNC
+
+# RUN: ld.lld --memtag-mode=sync --memtag-heap --memtag-stack %t.o -o %t
+# RUN: llvm-readelf -n %t | \
+# RUN:FileCheck %s --check-prefixes=NOTE,BOTH-SYNC
+
+# NOTE: .note.android.memtag
+# NOTE-NEXT: Owner
+# TODO(hctim): Update llvm-readelf to understand this note type.
+# NOTE-NEXT: Android  0x0004  Unknown note type: (0x0004)
+
+# The next few lines are an ABI enforcement for Android 11 and 12. If you're
+# compiling with just heap MTE (i.e just --memtag-mode), then these lines MUST
+# be unchanging.
+# HEAP-ASYNC-NOTE-NEXT: description data: 05 00 00 00
+# HEAP-SYNC-NOTE-NEXT: description data: 06 00 00 00
+
+# Stack MTE is, as of Android 12, unimplemented. However, we pre-emptively emit
+# a bit that signifies to the dynamic loader to map the primary and thread
+# stacks as PROT_MTE, in preparation for the bionic support.
+# STACK-ASYNC-NEXT: description data: 09 00 00 00
+# STACK-SYNC-NEXT: description data: 0a 00 00 00
+
+# Stack MTE is, as of Android 12, unimplemented. However, we pre-emptively emit
+# a bit that signifies to the dynamic loader to map the primary and thread
+# stacks as PROT_MTE, in preparation for the bionic support.
+# BOTH-ASYNC-NEXT: description data: 0d 00 00 00
+# BOTH-SYNC-NEXT: description data: 0e 00 00 00
+
+# RUN: not ld.lld --memtag-stack 2>&1 | \
+# RUN:FileCheck %s --check-prefix=MISSI

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

2022-02-09 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: eugenis.
Herald added subscribers: dexonsmith, hiraditya.
Herald added a reviewer: aaron.ballman.
hctim requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

Currently HWASan uses the no_sanitize shared with llvm.asan.globals to
disable hwasanification. The llvm.asan.globals list contains a whole
bunch of fluff (location, name, dynamically-initialized, excluded) in
order for dynamic initialization in ASan. We don't do that in HWASan,
globals have a static tag that's embedded in the file.

Right now, it's not possible for no_sanitize("hwaddress") to be slapped
on a global. Add this feature.

In addition, add the metadata to the global variable itself, as to
whether sanitization is disabled. Passes like GlobalOpt can replace the
existing global, and only copies the metadata for the GlobalVariable
itself, without replacing the GV pointers in llvm.asan.globals. This can
cause bugs, where no_sanitize("hwaddress") (and "address" as well, but
that's left for another time) ends up getting ignored if the global is
replaced.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119367

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/lib/Sema/SemaDeclAttr.cpp
  compiler-rt/test/hwasan/TestCases/global-with-reduction.c
  compiler-rt/test/hwasan/TestCases/global.c
  llvm/include/llvm/IR/GlobalValue.h
  llvm/lib/IR/Globals.cpp
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1717,34 +1717,10 @@
   GV->eraseFromParent();
 }
 
-static DenseSet getExcludedGlobals(Module &M) {
-  NamedMDNode *Globals = M.getNamedMetadata("llvm.asan.globals");
-  if (!Globals)
-return DenseSet();
-  DenseSet Excluded(Globals->getNumOperands());
-  for (auto MDN : Globals->operands()) {
-// Metadata node contains the global and the fields of "Entry".
-assert(MDN->getNumOperands() == 5);
-auto *V = mdconst::extract_or_null(MDN->getOperand(0));
-// The optimizer may optimize away a global entirely.
-if (!V)
-  continue;
-auto *StrippedV = V->stripPointerCasts();
-auto *GV = dyn_cast(StrippedV);
-if (!GV)
-  continue;
-ConstantInt *IsExcluded = mdconst::extract(MDN->getOperand(4));
-if (IsExcluded->isOne())
-  Excluded.insert(GV);
-  }
-  return Excluded;
-}
-
 void HWAddressSanitizer::instrumentGlobals() {
   std::vector Globals;
-  auto ExcludedGlobals = getExcludedGlobals(M);
   for (GlobalVariable &GV : M.globals()) {
-if (ExcludedGlobals.count(&GV))
+if (GV.isNoSanitize())
   continue;
 
 if (GV.isDeclarationForLinker() || GV.getName().startswith("llvm.") ||
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -69,6 +69,7 @@
   setDLLStorageClass(Src->getDLLStorageClass());
   setDSOLocal(Src->isDSOLocal());
   setPartition(Src->getPartition());
+  setNoSanitize(Src->isNoSanitize());
 }
 
 void GlobalValue::removeFromParent() {
Index: llvm/include/llvm/IR/GlobalValue.h
===
--- llvm/include/llvm/IR/GlobalValue.h
+++ llvm/include/llvm/IR/GlobalValue.h
@@ -80,14 +80,14 @@
 UnnamedAddrVal(unsigned(UnnamedAddr::None)),
 DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal),
 HasLLVMReservedName(false), IsDSOLocal(false), HasPartition(false),
-IntID((Intrinsic::ID)0U), Parent(nullptr) {
+NoSanitize(false), IntID((Intrinsic::ID)0U), Parent(nullptr) {
 setLinkage(Linkage);
 setName(Name);
   }
 
   Type *ValueType;
 
-  static const unsigned GlobalValueSubClassDataBits = 16;
+  static const unsigned GlobalValueSubClassDataBits = 15;
 
   // All bitfields use unsigned as the underlying type so that MSVC will pack
   // them.
@@ -112,9 +112,15 @@
   /// https://lld.llvm.org/Partitions.html).
   unsigned HasPartition : 1;
 
+  /// Should this variable be excluded from sanitization. Used for HWASan, so
+  /// that global variables can be marked as
+  /// __attribute__((no_sanitize("hwaddress"))), as well as ensuring that
+  /// markers for other sanitizers (e.g. ubsan) don't get sanitized.
+  unsigned NoSanitize : 1;
+
 private:
   // Give subclasses access to what otherwise would be wasted padding.
-  // (16 + 4 + 2 + 2 + 2 + 3 + 1 + 1 + 1) == 32.
+  // (15 + 4 + 2 + 2 + 2 + 3 + 1 + 1 + 1 + 1) == 32.
   unsigned SubClassData : GlobalValueSubClassDataBits;
 
   friend class Constant;
@@ -240,6 +246,9 @@
   s

[PATCH] D118948: [MTE] Add -fsanitize=memtag* and friends.

2022-02-09 Thread Mitch Phillips via Phabricator via cfe-commits
hctim planned changes to this revision.
hctim marked 8 inline comments as done.
hctim added a comment.

Pushed the [1/3] ELF note parsing over to D119381 
. Will leave this review for the clang-side 
changes, and send a new patch for the LLD changes. All of your comments are 
completed in my internal branch, and I'll upload that after the lld changes are 
landed.




Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:475
 def err_stack_tagging_requires_hardware_feature : Error<
-  "'-fsanitize=memtag' requires hardware support (+memtag)">;
+  "'-fsanitize=memtag-stack' requires hardware support (+memtag). For Armv8, "
+  "try compiling with -march=armv8a+memtag.">;

eugenis wrote:
> Split out renaming of memtag to memtag-stack first? This will remove a lot of 
> diff from this patch.
splitting into elf -> lld -> clang as per Ray's suggestion, should reduce the 
diff enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118948

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

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

> summary of DWARF:
> & how many of these descriptions get added to the debug info?

afaict, there is now:
 1x .debug_addr entry for each string
 1x. debug_info DW_TAG_variable for each string
 1x. DW_TAG_array_type + DW_TAG_subrange_type for each unique sizeof(string)

i tried to measure if there's other bits laying around that could be optimised. 
i thought briefly about diffing the llvm-dwarfdump for the before/after for 
clang, but as the dumpfiles reached 20gb, rethought that decision. the 
dwarfdump for the clang/test/CodeGen/debug-info-variables.c dwo is below.

> Numbers for Split DWARF may be helpful too - given this'll add an extra 
> address/relocation for every string literal, it might make object size 
> (specifically unlinked object size where relocations are expensive/plentiful) 
> significantly larger in problematic ways.

sorry, i don't understand why split-dwarf means this requires an additional 
relocation (i'm not really sure what split-dwarf is outside of just putting the 
dwarf in a separate file, but don't see why that would change relocations). i 
made a quick dwarfdump diff on clang/test/CodeGen/debug-info-variables.c (with 
split-dwarf):

sections old:

  [Nr] Name  TypeAddress  OffSize   ES Flg 
Lk Inf Al
  [ 2] .debug_str.dwoPROGBITS 40 eb 01 MSE  
0   0  1
  [ 3] .debug_str_offsets.dwo PROGBITS    00012b 2c 00   E  
0   0  1
  [ 4] .debug_info.dwo   PROGBITS 000157 77 00   E  
0   0  1
  [ 5] .debug_abbrev.dwo PROGBITS 0001ce 91 00   E  
0   0  1

sections new:

  [Nr] Name  TypeAddress  OffSize   ES Flg 
Lk Inf Al
  [ 3] .debug_str.dwoPROGBITS 78 ff 01 MSE  
0   0  1
  [ 2] .debug_str_offsets.dwo PROGBITS    40 38 00   E  
0   0  1
  [ 4] .debug_info.dwo   PROGBITS 000177 92 00   E  
0   0  1
  [ 5] .debug_abbrev.dwo PROGBITS 000209 aa 00   E  
0   0  1

so `.debug_string += 0x14`, `.debug_str_offsets += 0xc`, `.debug_info += 0x1b` 
and `.debug_abbrev += 0x19`.

as before, the DW_TAG_array_type + DW_TAG_subrange_type would be amortised 
across strings with the same size.

unfortunately, i don't see any further places to optimise (except for the full 
`const char*` amortization, which as in a previous comment, didn't make much of 
an improvement for the entire clang binary)

  diff --git a/tmp/dwo/dwo-dump b/dwo-dump
  index e0fdd77..6415086 100644
  --- a/tmp/dwo/dwo-dump
  +++ b/dwo-dump
  @@ -3,14 +3,13 @@ debug-info-variables.dwo:   file format elf64-x86-64
   .debug_abbrev.dwo contents:
   Abbrev table for offset: 0x
   [1] DW_TAG_compile_unit  DW_CHILDREN_yes
  - DW_AT_producer  DW_FORM_GNU_str_index
  + DW_AT_producer  DW_FORM_strx1
DW_AT_language  DW_FORM_data2
  - DW_AT_name  DW_FORM_GNU_str_index
  - DW_AT_GNU_dwo_name  DW_FORM_GNU_str_index
  - DW_AT_GNU_dwo_idDW_FORM_data8
  + DW_AT_name  DW_FORM_strx1
  + DW_AT_dwo_name  DW_FORM_strx1
   
   [2] DW_TAG_variable  DW_CHILDREN_no
  - DW_AT_name  DW_FORM_GNU_str_index
  + DW_AT_name  DW_FORM_strx1
DW_AT_type  DW_FORM_ref4
DW_AT_external  DW_FORM_flag_present
DW_AT_decl_file DW_FORM_data1
  @@ -18,155 +17,194 @@ Abbrev table for offset: 0x
DW_AT_location  DW_FORM_exprloc
   
   [3] DW_TAG_base_type DW_CHILDREN_no
  - DW_AT_name  DW_FORM_GNU_str_index
  + DW_AT_name  DW_FORM_strx1
DW_AT_encoding  DW_FORM_data1
DW_AT_byte_size DW_FORM_data1
   
  -[4] DW_TAG_subprogramDW_CHILDREN_no
  - DW_AT_low_pcDW_FORM_GNU_addr_index
  +[4] DW_TAG_variable  DW_CHILDREN_no
  + DW_AT_type  DW_FORM_ref4
  + DW_AT_decl_file DW_FORM_data1
  + DW_AT_decl_line DW_FORM_data1
  + DW_AT_location  DW_FORM_exprloc
  +
  +[5] DW_TAG_array_typeDW_CHILDREN_yes
  + DW_AT_type  DW_FORM_ref4
  +
  +[6] DW_TAG_subrange_type DW_CHILDREN_no
  + DW_AT_type  DW_FORM_ref4
  + DW_AT_count DW_FORM_data1
  +
  +[7] DW_TAG_base_type DW_CHILDREN_no
  + DW_AT_name  DW_FORM_strx1
  + DW_AT_byte_size DW_FORM_data1
  + DW_AT_encoding  DW_FORM_data1
  +
  +[8] DW_TAG_subprogramDW_CHILDREN_no
  + DW_AT_low_pcDW_FORM_addrx
DW_AT_high_pc   DW_FORM_data4
DW_AT_frame_baseDW_FORM_exprloc
  - DW_AT_name  DW_FORM_GNU_str_index
  + DW_AT_name  DW_FORM_strx1
DW_AT_decl_file DW_FORM_data1
DW_AT_decl_line DW_FORM_data1
DW_AT_type  DW_FORM_ref4
DW_AT_external  DW_FORM_flag_present
   
  -[5] DW_TAG_subprogramDW_CHILDREN_yes
  - DW_AT_low_pcDW_FORM_GNU_addr_index
  +[9] DW_TAG_subprogramDW_CHILDREN_yes
  + 

[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-26 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked an inline comment as done.
hctim added inline comments.



Comment at: clang/test/CodeGen/debug-info-variables.c:1
+// RUN: %clang_cc1 %s -debug-info-kind=standalone -S -emit-llvm -o - | 
FileCheck %s
+

dblaikie wrote:
> Presumably named variables are already tested elsewhere - so I probably 
> wouldn't test them here, and would give this file a more specific name 
> related to string literals. Alternatively/perhaps the other thing to do would 
> be to find some test that already covers global variable debug info, and test 
> string literals there?
I found `debug-info-global-constant.c` and `debug-info-static.c`, but neither 
of them test DILocalVariables or strings.

This test was cargo-culted from `debug-info-gline-tables-only.c` which does the 
inverse :).

I was hoping that this test would become the main "simple global variables" 
test :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D124493: [symbolizer] Parse DW_TAG_variable DIs to show line info for globals

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

Sorry for the large patch. Honestly, looks bigger than it is due to 1-line 
changes in many files + many-line changes in stuff that was pretty much moved 
around. I didn't see a great way to split this up except for sharding out the 
GlobalValue changes + IR + bitcode read/write, but didn't think that was 
substantial enough to warrant it.


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] D124493: [symbolizer] Parse DW_TAG_variable DIs to show line info for globals

2022-04-26 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 425379.
hctim added a comment.

Wrong base, updating.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124493

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/lib/CodeGen/SanitizerMetadataFactory.cpp
  clang/lib/CodeGen/SanitizerMetadataFactory.h
  clang/test/CodeGen/asan-globals-alias.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/asan-static-odr.cpp
  clang/test/CodeGen/asan-strings.c
  clang/test/CodeGen/sanitize-init-order.cpp
  clang/test/CodeGen/ubsan-strip-path-components.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  compiler-rt/lib/asan/asan_globals.cpp
  compiler-rt/lib/asan/asan_interface_internal.h
  compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp
  compiler-rt/test/asan/TestCases/Linux/odr-violation.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/AsmParser/LLParser.h
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.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/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

[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-29 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 426172.
hctim marked an inline comment as done.
hctim added a comment.
Herald added subscribers: rupprecht, MaskRay, emaste.
Herald added a reviewer: jhenderson.

Update test, rebase off of string debuginfo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

Files:
  llvm/include/llvm/DebugInfo/DIContext.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
  llvm/include/llvm/DebugInfo/PDB/PDBContext.h
  llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
  llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
  llvm/lib/DebugInfo/PDB/PDBContext.cpp
  llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
  llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
  llvm/test/DebugInfo/Symbolize/ELF/data-command-symtab.yaml
  llvm/test/tools/llvm-symbolizer/data-location.yaml
  llvm/test/tools/llvm-symbolizer/data.s

Index: llvm/test/tools/llvm-symbolizer/data.s
===
--- llvm/test/tools/llvm-symbolizer/data.s
+++ llvm/test/tools/llvm-symbolizer/data.s
@@ -7,9 +7,12 @@
 
 # CHECK:  d1
 # CHECK-NEXT: 0 8
+# CHECK-NEXT: ??:?
 # CHECK-EMPTY:
 # CHECK-NEXT: d2
 # CHECK-NEXT: 8 4
+# CHECK-NEXT: ??:?
+# CHECK-EMPTY:
 
 d1:
 .quad 0x1122334455667788
Index: llvm/test/tools/llvm-symbolizer/data-location.yaml
===
--- /dev/null
+++ llvm/test/tools/llvm-symbolizer/data-location.yaml
@@ -0,0 +1,503 @@
+## Show that when "DATA" is used with an address, it forces the found location
+## to be symbolized as data, including the source information.
+
+# RUN: yaml2obj %s -o %t.so
+
+# RUN: llvm-symbolizer "DATA 0x38a4" "DATA 0x3868" "DATA 0x38a0" \
+# RUN:   --obj=%t.so | FileCheck %s
+
+# CHECK:  bss_global
+# CHECK-NEXT: {{[0-9]+}} 4
+# CHECK-NEXT: /tmp/file.c:1
+# CHECK-EMPTY:
+# CHECK-NEXT: data_global
+# CHECK-NEXT: {{[0-9]+}} 4
+# CHECK-NEXT: /tmp/file.c:2
+# CHECK-EMPTY:
+# CHECK-NEXT: f.function_global
+# CHECK-NEXT: {{[0-9]+}} 4
+# CHECK-NEXT: /tmp/file.c:4
+# CHECK-EMPTY:
+
+
+## File below was generated using:
+##   $ clang -g -fuse-ld=lld -shared /tmp/file.c -o out.so && obj2yaml out.so
+## ... with /tmp/file.c:
+##   1: int bss_global;
+##   2: int data_global = 2;
+##   3: void f() {
+##   4:   static int function_global;
+##   5: }
+##   6:
+## ... then, one can get the offsets using `nm`, like:
+##   $ nm out.so | grep bss_global
+## 38fc B bss_global
+##
+## Ideally, this would be tested by invoking clang directly on a C source file,
+## but unfortunately there's no way to do that for LLVM tests. The other option
+## is to compile IR to an objfile, but llvm-symbolizer doesn't understand that
+## two symbols can have the same address in different sections. In the code
+## above, for example, we'd have bss_global at .bss+0x0, and data_global at
+## .data+0x0, and so the symbolizer would only print one of them. Hence, we have
+## the ugly dso-to-yaml blob below.
+##
+## For now, constant strings don't have a debuginfo entry, and so can't be
+## symbolized correctly. In future (if D123534 gets merged), this can be updated
+## to include a check that llvm-symbolize can also symbolize constant strings,
+## like `const char* string = "123456"` (and &"123456" should be symbolizable)
+## to the specific line. Then, you can find the address of the constant string
+## from the relocation:
+##   $ nm out.so | grep string
+## 38c0 D string
+##   $ llvm-objdump -R out.so | grep 38c0
+## 38c0 R_X86_64_RELATIVE *ABS*+0x4f8 # <-- 0x4f8
+
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_DYN
+  Machine: EM_X86_64
+ProgramHeaders:
+  - Type:PT_PHDR
+Flags:   [ PF_R ]
+VAddr:   0x40
+Align:   0x8
+  - Type:PT_LOAD
+Flags:   [ PF_R ]
+FirstSec:.dynsym
+LastSec: .eh_frame
+Align:   0x1000
+  - Type:PT_LOAD
+Flags:   [ PF_X, PF_R ]
+FirstSec:.text
+LastSec: .plt
+VAddr:   0x1510
+Align:   0x1000
+  - Type:PT_LOAD
+Flags:   [ PF_W, PF_R ]
+FirstSec:.ctors
+LastSec: .got
+VAddr:   0x26D0
+Align:   0x1000
+  - Type:PT_LOAD
+Flags:   [ PF_W, PF_R ]
+FirstSec:.data
+LastSec: .bss
+VAddr:   0x3860
+Align:   0x1000
+  - Type:PT_DYNAMIC
+Flags:   [ PF_W, PF_R ]
+FirstSec:.dynamic
+LastSec: .dynamic
+VAddr:   0x26F0
+Al

[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-29 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 426175.
hctim added a comment.

(restoring after uploading the diff for D123538 
 here accidentally)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/debug-info-variables.c
  clang/test/VFS/external-names.c
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -165,7 +165,9 @@
   } else {
 DeclContext = GV->getScope();
 // Add name and type.
-addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
+StringRef DisplayName = GV->getDisplayName();
+if (!DisplayName.empty())
+  addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
 if (GTy)
   addType(*VariableDIE, GTy);
 
Index: clang/test/VFS/external-names.c
===
--- clang/test/VFS/external-names.c
+++ clang/test/VFS/external-names.c
@@ -30,8 +30,8 @@
 // Debug info
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG-EXTERNAL %s
-// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num:[0-9]+]]
-// CHECK-DEBUG-EXTERNAL: ![[Num]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: ![[Num:[0-9]+]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num]]
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG %s
 // CHECK-DEBUG-NOT: Inputs
Index: clang/test/CodeGen/debug-info-variables.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-variables.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -debug-info-kind=standalone -S -emit-llvm -o - | FileCheck %s
+
+// CHECK: DIGlobalVariable(name: "global"
+int global = 42;
+
+// CHECK: DIGlobalVariable({{.*}}line: [[@LINE+2]]
+const char* s() {
+  return "1234567890";
+}
+
+// CHECK: DILocalVariable(name: "p"
+// CHECK: DILocalVariable(name: "q"
+// CHECK: DILocalVariable(name: "r"
+int sum(int p, int q) {
+  int r = p + q;
+  return r;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5659,6 +5659,11 @@
   }
 
   auto GV = GenerateStringLiteral(C, LT, *this, GlobalVariableName, Alignment);
+
+  CGDebugInfo *DI = getModuleDebugInfo();
+  if (DI && getCodeGenOpts().hasReducedDebugInfo())
+DI->AddStringLiteralDebugInfo(GV, GlobalVariableName, S);
+
   if (Entry)
 *Entry = GV;
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -533,6 +533,10 @@
   /// Emit an @import declaration.
   void EmitImportDecl(const ImportDecl &ID);
 
+  /// Create and attach debuginfo to a the provided string literal GV.
+  void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV, StringRef Name,
+ const StringLiteral *S);
+
   /// Emit C++ namespace alias.
   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5131,7 +5131,7 @@
 return Name;
   codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
   CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
-  
+
   if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
 TemplateNamesKind = codegenoptions::DebugTemplateNamesKind::Full;
 
@@ -5458,6 +5458,22 @@
   ImportedDeclCache[GD.getCanonicalDecl().getDecl()].reset(ImportDI);
 }
 
+void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
+StringRef Name,
+const StringLiteral *S) {
+  SourceLocation Loc = S->getStrTokenLoc(0);
+  PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
+  if (!PLoc.isValid())
+return;
+
+  llvm::DIFile *File = getOrCreateFile(Loc);
+  llvm::DIGlobalVariableExpression *Debug =
+  DBuilder.createGlobalVariableExpression(
+  nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
+  getLineNumber(Loc), getOrCreateType(S->getType(), F

[PATCH] D123538: [symbolizer] Parse DW_TAG_variable DIs to show line info for globals

2022-04-29 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 426176.
hctim added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

(restoring after uploading the diff for D123534 
 here accidentally)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123538

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/debug-info-variables.c
  clang/test/VFS/external-names.c
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -165,7 +165,9 @@
   } else {
 DeclContext = GV->getScope();
 // Add name and type.
-addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
+StringRef DisplayName = GV->getDisplayName();
+if (!DisplayName.empty())
+  addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
 if (GTy)
   addType(*VariableDIE, GTy);
 
Index: clang/test/VFS/external-names.c
===
--- clang/test/VFS/external-names.c
+++ clang/test/VFS/external-names.c
@@ -30,8 +30,8 @@
 // Debug info
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG-EXTERNAL %s
-// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num:[0-9]+]]
-// CHECK-DEBUG-EXTERNAL: ![[Num]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: ![[Num:[0-9]+]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
+// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num]]
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG %s
 // CHECK-DEBUG-NOT: Inputs
Index: clang/test/CodeGen/debug-info-variables.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-variables.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -debug-info-kind=standalone -S -emit-llvm -o - | FileCheck %s
+
+// CHECK: DIGlobalVariable(name: "global"
+int global = 42;
+
+// CHECK: DIGlobalVariable({{.*}}line: [[@LINE+2]]
+const char* s() {
+  return "1234567890";
+}
+
+// CHECK: DILocalVariable(name: "p"
+// CHECK: DILocalVariable(name: "q"
+// CHECK: DILocalVariable(name: "r"
+int sum(int p, int q) {
+  int r = p + q;
+  return r;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5659,6 +5659,11 @@
   }
 
   auto GV = GenerateStringLiteral(C, LT, *this, GlobalVariableName, Alignment);
+
+  CGDebugInfo *DI = getModuleDebugInfo();
+  if (DI && getCodeGenOpts().hasReducedDebugInfo())
+DI->AddStringLiteralDebugInfo(GV, GlobalVariableName, S);
+
   if (Entry)
 *Entry = GV;
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -533,6 +533,10 @@
   /// Emit an @import declaration.
   void EmitImportDecl(const ImportDecl &ID);
 
+  /// Create and attach debuginfo to a the provided string literal GV.
+  void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV, StringRef Name,
+ const StringLiteral *S);
+
   /// Emit C++ namespace alias.
   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5131,7 +5131,7 @@
 return Name;
   codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
   CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
-  
+
   if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
 TemplateNamesKind = codegenoptions::DebugTemplateNamesKind::Full;
 
@@ -5458,6 +5458,22 @@
   ImportedDeclCache[GD.getCanonicalDecl().getDecl()].reset(ImportDI);
 }
 
+void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
+StringRef Name,
+const StringLiteral *S) {
+  SourceLocation Loc = S->getStrTokenLoc(0);
+  PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
+  if (!PLoc.isValid())
+return;
+
+  llvm::DIFile *File = getOrCreateFile(Loc);
+  llvm::DIGlobalVariableExpression *Debug =
+  DBuilder.createGlobalVariableExpression(
+  nullptr, StringRef(), StringRef(), getOrCreateFi

[PATCH] D123538: [symbolizer] Parse DW_TAG_variable DIs to show line info for globals

2022-04-29 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 426177.
hctim added a comment.

(restoring after uploading the diff for D123534 
 here accidentally)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123538

Files:
  llvm/include/llvm/DebugInfo/DIContext.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
  llvm/include/llvm/DebugInfo/PDB/PDBContext.h
  llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
  llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
  llvm/lib/DebugInfo/PDB/PDBContext.cpp
  llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
  llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
  llvm/test/DebugInfo/Symbolize/ELF/data-command-symtab.yaml
  llvm/test/tools/llvm-symbolizer/data-location.yaml
  llvm/test/tools/llvm-symbolizer/data.s

Index: llvm/test/tools/llvm-symbolizer/data.s
===
--- llvm/test/tools/llvm-symbolizer/data.s
+++ llvm/test/tools/llvm-symbolizer/data.s
@@ -7,9 +7,12 @@
 
 # CHECK:  d1
 # CHECK-NEXT: 0 8
+# CHECK-NEXT: ??:?
 # CHECK-EMPTY:
 # CHECK-NEXT: d2
 # CHECK-NEXT: 8 4
+# CHECK-NEXT: ??:?
+# CHECK-EMPTY:
 
 d1:
 .quad 0x1122334455667788
Index: llvm/test/tools/llvm-symbolizer/data-location.yaml
===
--- /dev/null
+++ llvm/test/tools/llvm-symbolizer/data-location.yaml
@@ -0,0 +1,503 @@
+## Show that when "DATA" is used with an address, it forces the found location
+## to be symbolized as data, including the source information.
+
+# RUN: yaml2obj %s -o %t.so
+
+# RUN: llvm-symbolizer "DATA 0x38a4" "DATA 0x3868" "DATA 0x38a0" \
+# RUN:   --obj=%t.so | FileCheck %s
+
+# CHECK:  bss_global
+# CHECK-NEXT: {{[0-9]+}} 4
+# CHECK-NEXT: /tmp/file.c:1
+# CHECK-EMPTY:
+# CHECK-NEXT: data_global
+# CHECK-NEXT: {{[0-9]+}} 4
+# CHECK-NEXT: /tmp/file.c:2
+# CHECK-EMPTY:
+# CHECK-NEXT: f.function_global
+# CHECK-NEXT: {{[0-9]+}} 4
+# CHECK-NEXT: /tmp/file.c:4
+# CHECK-EMPTY:
+
+
+## File below was generated using:
+##   $ clang -g -fuse-ld=lld -shared /tmp/file.c -o out.so && obj2yaml out.so
+## ... with /tmp/file.c:
+##   1: int bss_global;
+##   2: int data_global = 2;
+##   3: void f() {
+##   4:   static int function_global;
+##   5: }
+##   6:
+## ... then, one can get the offsets using `nm`, like:
+##   $ nm out.so | grep bss_global
+## 38fc B bss_global
+##
+## Ideally, this would be tested by invoking clang directly on a C source file,
+## but unfortunately there's no way to do that for LLVM tests. The other option
+## is to compile IR to an objfile, but llvm-symbolizer doesn't understand that
+## two symbols can have the same address in different sections. In the code
+## above, for example, we'd have bss_global at .bss+0x0, and data_global at
+## .data+0x0, and so the symbolizer would only print one of them. Hence, we have
+## the ugly dso-to-yaml blob below.
+##
+## For now, constant strings don't have a debuginfo entry, and so can't be
+## symbolized correctly. In future (if D123534 gets merged), this can be updated
+## to include a check that llvm-symbolize can also symbolize constant strings,
+## like `const char* string = "123456"` (and &"123456" should be symbolizable)
+## to the specific line. Then, you can find the address of the constant string
+## from the relocation:
+##   $ nm out.so | grep string
+## 38c0 D string
+##   $ llvm-objdump -R out.so | grep 38c0
+## 38c0 R_X86_64_RELATIVE *ABS*+0x4f8 # <-- 0x4f8
+
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_DYN
+  Machine: EM_X86_64
+ProgramHeaders:
+  - Type:PT_PHDR
+Flags:   [ PF_R ]
+VAddr:   0x40
+Align:   0x8
+  - Type:PT_LOAD
+Flags:   [ PF_R ]
+FirstSec:.dynsym
+LastSec: .eh_frame
+Align:   0x1000
+  - Type:PT_LOAD
+Flags:   [ PF_X, PF_R ]
+FirstSec:.text
+LastSec: .plt
+VAddr:   0x1510
+Align:   0x1000
+  - Type:PT_LOAD
+Flags:   [ PF_W, PF_R ]
+FirstSec:.ctors
+LastSec: .got
+VAddr:   0x26D0
+Align:   0x1000
+  - Type:PT_LOAD
+Flags:   [ PF_W, PF_R ]
+FirstSec:.data
+LastSec: .bss
+VAddr:   0x3860
+Align:   0x1000
+  - Type:PT_DYNAMIC
+Flags:   [ PF_W, PF_R ]
+FirstSec:.dynamic
+LastSec: .dynamic
+VAddr:   0x26F0
+Align:   0x8
+  - Type:PT_GNU_RELRO
+Flags:

[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] 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] 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] 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] 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-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-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] 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] 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] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-05-10 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D123534#3489262 , @dblaikie wrote:

> @rnk @aprantl @probinson: this looks plausible to me to take as a general 
> change to the emitted DWARF, but I'm open to ideas/suggestions if folks find 
> this to be too much growth for not enough benefit & that it should be behind 
> a flag?

Friendly ping @rnk @aprantl @probinson, do you folks have any feedback?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


  1   2   3   >