[PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis created this revision. eugenis added reviewers: kcc, pcc. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. Clang-side cross-DSO CFI. * Enabled with -fsanitize-cfi-cross-dso * uses a runtime library, unlike "plain" CFI * does not yet support diagnostics * Emits __cfi_slowpath calls if bitset test fails. This routes the check to the target module, which may know more about the runtime type of the object or function. * Set a module flag to enable __cfi_check generation during LTO. Repository: rL LLVM http://reviews.llvm.org/D15367 Files: include/clang/Driver/Options.td include/clang/Driver/SanitizerArgs.h include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/Driver/SanitizerArgs.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/Driver/fsanitize.c test/Driver/sanitizer-ld.c Index: test/Driver/sanitizer-ld.c === --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -291,6 +291,46 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// CFI by itself does not link runtime libraries. +// RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-LINUX %s +// CHECK-CFI-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-LINUX-NOT: libclang_rt. + +// CFI with diagnostics links the UBSan runtime. +// RUN: %clang -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: %s -### -o %t.o 2>&1\ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s +// CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI links the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s +// CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI with diagnostics links just the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. + // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ // RUN: -target x86_64-apple-darwin13.4.0 \ Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -263,6 +263,15 @@ // CHECK-CFI-NOTRAP-WIN: -emit-llvm-bc // CHECK-CFI-NOTRAP-WIN-NOT: -fsanitize-trap=cfi +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -fno-sanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// CHECK-CFI-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-CROSS-DSO: -fsanitize-cfi-cross-dso +// CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL Index: test/CodeGenCXX/cfi-cross-dso.cpp ===
Re: [PATCH] D14409: Remove visibility attributes from out-of-class method definitions in iostreams.
eugenis added a comment. Hi, Have you had a chance to look at this? Repository: rL LLVM http://reviews.llvm.org/D14409 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15208: Patch for inline abort code generation
eugenis added a comment. I misunderstood the meaning of -fsanitize-trap, and now I prefer -fsanitize-merge-traps for the flag name. Repository: rL LLVM http://reviews.llvm.org/D15208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15246: [Docs] Update MSan docs
eugenis accepted this revision. This revision is now accepted and ready to land. Comment at: docs/MemorySanitizer.rst:109 @@ -107,3 +108,3 @@ MemorySanitizer can track origins of unitialized values, similar to Valgrind's --track-origins option. This feature is enabled by uninitialized Comment at: docs/MemorySanitizer.rst:188 @@ -171,3 +187,3 @@ -* Linux x86\_64 (tested on Ubuntu 12.04); +* Linux x86\_64/MIPS64/AArch64 (tested on Ubuntu 12.04); 14.04, too maybe not mention the version at all? http://reviews.llvm.org/D15246 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14409: Remove visibility attributes from out-of-class method definitions in iostreams.
eugenis added a comment. In http://reviews.llvm.org/D14409#306272, @EricWF wrote: > Does the `inline` keyword have any effect when it's on function definitions > that are externally instantiated? I could not detect any difference in behavior with or without inline keyword. Remove it? Repository: rL LLVM http://reviews.llvm.org/D14409 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15395: Add 3 more missing inline/visibility attributes
eugenis created this revision. eugenis added reviewers: EricWF, mclow.lists. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. These are the cases when an out-of-class definition of a method is marked _LIBCPP_INLINE_VISIBILITY, but the in-class declaration is not. This will start failing when (or if) we switch to __attribute__((internal_linkage)). Repository: rL LLVM http://reviews.llvm.org/D15395 Files: include/bitset include/memory Index: include/memory === --- include/memory +++ include/memory @@ -3995,6 +3995,7 @@ is_convertible<_Yp*, element_type*>::value, shared_ptr& >::type +_LIBCPP_INLINE_VISIBILITY operator=(auto_ptr<_Yp> __r); #endif template @@ -4008,6 +4009,7 @@ _LIBCPP_INLINE_VISIBILITY operator=(unique_ptr<_Yp, _Dp>&& __r); #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +_LIBCPP_INLINE_VISIBILITY operator=(unique_ptr<_Yp, _Dp> __r); #endif Index: include/bitset === --- include/bitset +++ include/bitset @@ -202,6 +202,7 @@ private: #ifdef _LIBCPP_HAS_NO_CONSTEXPR void __init(unsigned long long __v, false_type) _NOEXCEPT; +_LIBCPP_INLINE_VISIBILITY void __init(unsigned long long __v, true_type) _NOEXCEPT; #endif // _LIBCPP_HAS_NO_CONSTEXPR unsigned long to_ulong(false_type) const; Index: include/memory === --- include/memory +++ include/memory @@ -3995,6 +3995,7 @@ is_convertible<_Yp*, element_type*>::value, shared_ptr& >::type +_LIBCPP_INLINE_VISIBILITY operator=(auto_ptr<_Yp> __r); #endif template @@ -4008,6 +4009,7 @@ _LIBCPP_INLINE_VISIBILITY operator=(unique_ptr<_Yp, _Dp>&& __r); #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +_LIBCPP_INLINE_VISIBILITY operator=(unique_ptr<_Yp, _Dp> __r); #endif Index: include/bitset === --- include/bitset +++ include/bitset @@ -202,6 +202,7 @@ private: #ifdef _LIBCPP_HAS_NO_CONSTEXPR void __init(unsigned long long __v, false_type) _NOEXCEPT; +_LIBCPP_INLINE_VISIBILITY void __init(unsigned long long __v, true_type) _NOEXCEPT; #endif // _LIBCPP_HAS_NO_CONSTEXPR unsigned long to_ulong(false_type) const; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15395: Add 3 more missing inline/visibility attributes
eugenis closed this revision. eugenis added a comment. r255166 Repository: rL LLVM http://reviews.llvm.org/D15395 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15395: Add 3 more missing inline/visibility attributes
eugenis added a comment. Should be fine. Repository: rL LLVM http://reviews.llvm.org/D15395 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14409: Remove visibility attributes from out-of-class method definitions in iostreams.
eugenis closed this revision. eugenis added a comment. r255177 Thanks for the review! Repository: rL LLVM http://reviews.llvm.org/D14409 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxxabi] r255186 - Replace cmake check for printf with a check for fopen.
Author: eugenis Date: Wed Dec 9 18:44:42 2015 New Revision: 255186 URL: http://llvm.org/viewvc/llvm-project?rev=255186=rev Log: Replace cmake check for printf with a check for fopen. Printf is a builtin, and the check fails with -Werror because of a clang warning about an incompatible redeclaration. Modified: libcxxabi/trunk/cmake/config-ix.cmake Modified: libcxxabi/trunk/cmake/config-ix.cmake URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/cmake/config-ix.cmake?rev=255186=255185=255186=diff == --- libcxxabi/trunk/cmake/config-ix.cmake (original) +++ libcxxabi/trunk/cmake/config-ix.cmake Wed Dec 9 18:44:42 2015 @@ -39,7 +39,7 @@ check_cxx_compiler_flag(/EHa- check_cxx_compiler_flag(/GR- LIBCXXABI_HAS_NO_GR_FLAG) # Check libraries -check_library_exists(c printf "" LIBCXXABI_HAS_C_LIB) +check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB) check_library_exists(dl dladdr "" LIBCXXABI_HAS_DL_LIB) check_library_exists(pthread pthread_once "" LIBCXXABI_HAS_PTHREAD_LIB) check_library_exists(gcc_eh _Unwind_GetRegionStart "" LIBCXXABI_HAS_GCC_EH_LIB) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14411: Use __attribute__((internal_linkage)) when available.
eugenis added a dependency: D12502: [libcxx] Better constain tuples constructors -- Fix PR23256 and PR22806. eugenis added a comment. Note, this breaks tuple_cat.pass.cpp test. With -O0, replacing always_inline with internal_linkage results in less optimization being done (namely, no inlining happens). This ends up exposing https://llvm.org/bugs/show_bug.cgi?id=23256 which is fixed by http://reviews.llvm.org/D12502 The same failure can be reproduced in the current ToT libc++ by running this test with -O2. This change depends on http://reviews.llvm.org/D12502. Repository: rL LLVM http://reviews.llvm.org/D14411 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15404: Cleanup: move visibility/linkage attributes to the first declaration (part 2).
eugenis created this revision. eugenis added reviewers: EricWF, mclow.lists. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. This is a follow-up to r252385. For some reason, I missed a lot of cases when the visibility attribute was applied to the definition, but not to an earlier declaration. Repository: rL LLVM http://reviews.llvm.org/D15404 Files: include/complex include/experimental/any include/experimental/dynarray include/ext/hash_map include/ext/hash_set include/forward_list include/fstream include/list include/queue include/unordered_map include/unordered_set test/libcxx/test/config.py Index: test/libcxx/test/config.py === --- test/libcxx/test/config.py +++ test/libcxx/test/config.py @@ -364,6 +364,7 @@ self.cxx.compile_flags += shlex.split(compile_flags_str) sysroot_flags = getSysrootFlagsOnDarwin(self.config, self.lit_config) self.cxx.compile_flags.extend(sysroot_flags) + self.cxx.compile_flags.append("-ferror-limit=0") def configure_default_compile_flags(self): # Try and get the std version from the command line. Fall back to Index: include/unordered_set === --- include/unordered_set +++ include/unordered_set @@ -404,10 +404,12 @@ size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {} #endif +_LIBCPP_INLINE_VISIBILITY explicit unordered_set(const allocator_type& __a); unordered_set(const unordered_set& __u); unordered_set(const unordered_set& __u, const allocator_type& __a); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +_LIBCPP_INLINE_VISIBILITY unordered_set(unordered_set&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); unordered_set(unordered_set&& __u, const allocator_type& __a); @@ -439,10 +441,12 @@ return *this; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +_LIBCPP_INLINE_VISIBILITY unordered_set& operator=(unordered_set&& __u) _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); #endif #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +_LIBCPP_INLINE_VISIBILITY unordered_set& operator=(initializer_list __il); #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS @@ -527,6 +531,7 @@ #endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template +_LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __first, _InputIterator __last); #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY @@ -678,7 +683,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const allocator_type& __a) : __table_(__a) @@ -715,7 +720,7 @@ #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline _LIBCPP_INLINE_VISIBILITY +inline unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( unordered_set&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) @@ -792,7 +797,7 @@ #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline _LIBCPP_INLINE_VISIBILITY +inline unordered_set<_Value, _Hash, _Pred, _Alloc>& unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u) _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) @@ -806,7 +811,7 @@ #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS template -inline _LIBCPP_INLINE_VISIBILITY +inline unordered_set<_Value, _Hash, _Pred, _Alloc>& unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=( initializer_list __il) @@ -819,7 +824,7 @@ template template -inline _LIBCPP_INLINE_VISIBILITY +inline void unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) @@ -940,10 +945,12 @@ size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {} #endif +_LIBCPP_INLINE_VISIBILITY explicit unordered_multiset(const allocator_type& __a); unordered_multiset(const unordered_multiset& __u); unordered_multiset(const unordered_multiset& __u, const allocator_type& __a); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +_LIBCPP_INLINE_VISIBILITY unordered_multiset(unordered_multiset&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); unordered_multiset(unordered_multiset&& __u, const allocator_type& __a); @@ -973,6 +980,7 @@ return *this; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +_LIBCPP_INLINE_VISIBILITY unordered_multiset& operator=(unordered_multiset&& __u) _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); #endif @@ -1029,6 +1037,7 @@
Re: [PATCH] D14411: Use __attribute__((internal_linkage)) when available.
eugenis added a dependency: D15404: Cleanup: move visibility/linkage attributes to the first declaration (part 2).. eugenis added a comment. This change depends on http://reviews.llvm.org/D15404. Repository: rL LLVM http://reviews.llvm.org/D14411 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14409: Remove visibility attributes from out-of-class method definitions in iostreams.
eugenis added a comment. In http://reviews.llvm.org/D14409#306379, @eugenis wrote: > In http://reviews.llvm.org/D14409#306272, @EricWF wrote: > > > Does the `inline` keyword have any effect when it's on function definitions > > that are externally instantiated? > > > I could not detect any difference in behavior with or without inline keyword. > Remove it? Actually, remove the inline breaks tests, because now the method is declared hidden (in-class), so template instantiation in libc++.so produces a hidden symbol. As an alternative, we could remove both "inline" and the in-class hidden attribute. Repository: rL LLVM http://reviews.llvm.org/D14409 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14409: Remove visibility attributes from out-of-class method definitions in iostreams.
eugenis added a comment. In http://reviews.llvm.org/D14409#306531, @eugenis wrote: > In http://reviews.llvm.org/D14409#306379, @eugenis wrote: > > > In http://reviews.llvm.org/D14409#306272, @EricWF wrote: > > > > > Does the `inline` keyword have any effect when it's on function > > > definitions that are externally instantiated? > > > > > > I could not detect any difference in behavior with or without inline > > keyword. > > Remove it? > > > Actually, remove the inline breaks tests, because now the method is declared > hidden (in-class), so template instantiation in libc++.so produces a hidden > symbol. > > As an alternative, we could remove both "inline" and the in-class hidden > attribute. So, we can not remove "inline" because without it always_inline does not seem to have any effect. We can remove always_inline from the declarations, but that would add a few more exported symbols to libc++. I'll land this change as is, if you don't mind. Repository: rL LLVM http://reviews.llvm.org/D14409 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r255177 - Remove visibility attributes from out-of-class method definitions in iostreams.
Author: eugenis Date: Wed Dec 9 17:42:30 2015 New Revision: 255177 URL: http://llvm.org/viewvc/llvm-project?rev=255177=rev Log: Remove visibility attributes from out-of-class method definitions in iostreams. No point in pretending that these methods are hidden - they are actually exported from libc++.so. Extern template declarations make them part of libc++ ABI. This patch does not change libc++.so export list (at least on Linux). Modified: libcxx/trunk/include/istream libcxx/trunk/include/ostream libcxx/trunk/include/sstream libcxx/trunk/include/streambuf Modified: libcxx/trunk/include/istream URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/istream?rev=255177=255176=255177=diff == --- libcxx/trunk/include/istream (original) +++ libcxx/trunk/include/istream Wed Dec 9 17:42:30 2015 @@ -304,7 +304,7 @@ basic_istream<_CharT, _Traits>::sentry:: } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf* __sb) : __gc_(0) { @@ -314,7 +314,7 @@ basic_istream<_CharT, _Traits>::basic_is #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) : __gc_(__rhs.__gc_) { @@ -323,7 +323,7 @@ basic_istream<_CharT, _Traits>::basic_is } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) { @@ -339,7 +339,7 @@ basic_istream<_CharT, _Traits>::~basic_i } template -inline _LIBCPP_INLINE_VISIBILITY +inline void basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs) { @@ -725,7 +725,7 @@ basic_istream<_CharT, _Traits>::operator } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&)) { @@ -733,7 +733,7 @@ basic_istream<_CharT, _Traits>::operator } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(basic_ios & (*__pf)(basic_ios &)) @@ -743,7 +743,7 @@ basic_istream<_CharT, _Traits>::operator } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&)) { @@ -800,7 +800,7 @@ operator>>(basic_istream<_CharT, _Traits } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream & operator>>(basic_istream & __is, unsigned char* __s) { @@ -808,7 +808,7 @@ operator>>(basic_istream & } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream & operator>>(basic_istream & __is, signed char* __s) { @@ -843,7 +843,7 @@ operator>>(basic_istream<_CharT, _Traits } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream & operator>>(basic_istream & __is, unsigned char& __c) { @@ -851,7 +851,7 @@ operator>>(basic_istream & } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream & operator>>(basic_istream & __is, signed char& __c) { @@ -947,7 +947,7 @@ basic_istream<_CharT, _Traits>::get() } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type& __c) { @@ -1006,7 +1006,7 @@ basic_istream<_CharT, _Traits>::get(char } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n) { @@ -1068,7 +1068,7 @@ basic_istream<_CharT, _Traits>::get(basi } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(basic_streambuf & __sb) { @@ -1129,7 +1129,7 @@ basic_istream<_CharT, _Traits>::getline( } template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n) { @@ -1462,7 +1462,7 @@ ws(basic_istream<_CharT, _Traits>& __is) #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) { @@ -1504,7 +1504,7 @@ public: }; template -inline _LIBCPP_INLINE_VISIBILITY +inline basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf * __sb) : basic_istream<_CharT, _Traits>(__sb) { @@ -1513,14 +1513,14 @@ basic_iostream<_CharT, _Traits>::basic_i #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline
Re: [PATCH] D14411: Use __attribute__((internal_linkage)) when available.
eugenis added a comment. In http://reviews.llvm.org/D14411#306722, @EricWF wrote: > In http://reviews.llvm.org/D14411#306716, @EricWF wrote: > > > Why does this depend on http://reviews.llvm.org/D15404? > > > Woops, I meant the tuple patch but I see the other comment now. I'm curious > as to how inlininging ends up affecting which overload's SFINAE are evaluated. As I understand, in that test we pick a default(?) constructor instead of a move(?) constructor, and end up reading uninitialized memory. Then any code change can affect the test result. Like adding -O2 does, for example. > Drive by comment: Is the change from > `__attribute__((__visibility__("hidden"), __always_inline__))` to > `__attribute__((__internal_linkage__))` ABI compatible? I think so. I'll verify tomorrow. Repository: rL LLVM http://reviews.llvm.org/D14411 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15433: [libcxx] Remove inline/visibility attributes from exported template methods in valarray.
eugenis created this revision. eugenis added a reviewer: EricWF. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. This does not affect the libc++ export list now. It is required for internal_linkage switch to not affect the libc++ export list. This patch is on top of D15432. Repository: rL LLVM http://reviews.llvm.org/D15433 Files: include/valarray Index: include/valarray === --- include/valarray +++ include/valarray @@ -802,7 +802,6 @@ // construct/destroy: _LIBCPP_INLINE_VISIBILITY valarray() : __begin_(0), __end_(0) {} -_LIBCPP_INLINE_VISIBILITY explicit valarray(size_t __n); _LIBCPP_INLINE_VISIBILITY valarray(const value_type& __x, size_t __n); @@ -820,7 +819,6 @@ valarray(const mask_array& __ma); valarray(const indirect_array& __ia); -_LIBCPP_INLINE_VISIBILITY ~valarray(); // assignment: @@ -1092,16 +1090,14 @@ template -inline valarray<_Tp>::valarray(size_t __n) : __begin_(0), __end_(0) { resize(__n); } template -inline valarray<_Tp>::~valarray() { resize(0); Index: include/valarray === --- include/valarray +++ include/valarray @@ -802,7 +802,6 @@ // construct/destroy: _LIBCPP_INLINE_VISIBILITY valarray() : __begin_(0), __end_(0) {} -_LIBCPP_INLINE_VISIBILITY explicit valarray(size_t __n); _LIBCPP_INLINE_VISIBILITY valarray(const value_type& __x, size_t __n); @@ -820,7 +819,6 @@ valarray(const mask_array& __ma); valarray(const indirect_array& __ia); -_LIBCPP_INLINE_VISIBILITY ~valarray(); // assignment: @@ -1092,16 +1090,14 @@ template -inline valarray<_Tp>::valarray(size_t __n) : __begin_(0), __end_(0) { resize(__n); } template -inline valarray<_Tp>::~valarray() { resize(0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14411: Use __attribute__((internal_linkage)) when available.
eugenis added dependencies: D15433: [libcxx] Remove inline/visibility attributes from exported template methods in valarray., D15432: [libcxx] Move member function definition before it's explicit template instantiation declaration in to satisfy GCC.. eugenis added a comment. Depends on http://reviews.llvm.org/D15432. Depends on http://reviews.llvm.org/D15433. With all that change, the switch to internal_linkage attribute removes 3 symbols from the libc++ export table, all in basic_string: insert(..., InputIterator insert(..., ForwardIterator replace(..., InputIterator These are template methods of a template class. They are instantiated only in functions/methods that are marked with LIBCPP_INLINE_VISIBILITY; normally they are exported as linkonce_odr; after the internal_linkage switch they are not instantiated at all because their callers are never evaluated. Do you think this is an ABI break? Repository: rL LLVM http://reviews.llvm.org/D14411 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r255827 - Fix CFI tests in sanitizer-ld.
Author: eugenis Date: Wed Dec 16 16:03:39 2015 New Revision: 255827 URL: http://llvm.org/viewvc/llvm-project?rev=255827=rev Log: Fix CFI tests in sanitizer-ld. This test is not testing what it is supposed to test because of a mixup with the CHECK lines. Modified: cfe/trunk/test/Driver/sanitizer-ld.c Modified: cfe/trunk/test/Driver/sanitizer-ld.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=255827=255826=255827=diff == --- cfe/trunk/test/Driver/sanitizer-ld.c (original) +++ cfe/trunk/test/Driver/sanitizer-ld.c Wed Dec 16 16:03:39 2015 @@ -306,9 +306,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s // CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" -// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. -// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan -// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: "-whole-archive" "{{[^"]*}}libclang_rt.ubsan_standalone-x86_64.a" "-no-whole-archive" // Cross-DSO CFI links the CFI runtime. // RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ @@ -316,9 +314,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s // CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" -// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. -// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi- -// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: "-whole-archive" "{{[^"]*}}libclang_rt.cfi-x86_64.a" "-no-whole-archive" // Cross-DSO CFI with diagnostics links just the CFI runtime. // RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ @@ -327,9 +323,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" -// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. -// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi_diag- -// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "-whole-archive" "{{[^"]*}}libclang_rt.cfi_diag-x86_64.a" "-no-whole-archive" // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis added a comment. added some docs Comment at: lib/CodeGen/CodeGenModule.cpp:1041 @@ -988,3 +1040,3 @@ void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) { assert(!GV->isDeclaration() && "Only globals with definition can force usage."); pcc wrote: > What about callers of `EmitCfiSlowPathCheck`? updated Comment at: lib/CodeGen/CodeGenModule.cpp:1041 @@ -988,3 +1040,3 @@ void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) { assert(!GV->isDeclaration() && "Only globals with definition can force usage."); eugenis wrote: > pcc wrote: > > What about callers of `EmitCfiSlowPathCheck`? > updated fixed Repository: rL LLVM http://reviews.llvm.org/D15367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis updated this revision to Diff 42806. eugenis marked 2 inline comments as done. Repository: rL LLVM http://reviews.llvm.org/D15367 Files: docs/ControlFlowIntegrity.rst docs/ControlFlowIntegrityDesign.rst include/clang/Driver/Options.td include/clang/Driver/SanitizerArgs.h include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGVTables.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/MicrosoftCXXABI.cpp lib/Driver/SanitizerArgs.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/Driver/fsanitize.c test/Driver/sanitizer-ld.c Index: test/Driver/sanitizer-ld.c === --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -291,6 +291,46 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// CFI by itself does not link runtime libraries. +// RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-LINUX %s +// CHECK-CFI-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-LINUX-NOT: libclang_rt. + +// CFI with diagnostics links the UBSan runtime. +// RUN: %clang -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: %s -### -o %t.o 2>&1\ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s +// CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI links the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s +// CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI with diagnostics links just the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. + // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ // RUN: -target x86_64-apple-darwin13.4.0 \ Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -263,6 +263,15 @@ // CHECK-CFI-NOTRAP-WIN: -emit-llvm-bc // CHECK-CFI-NOTRAP-WIN-NOT: -fsanitize-trap=cfi +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -fno-sanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// CHECK-CFI-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-CROSS-DSO: -fsanitize-cfi-cross-dso +// CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- /dev/null +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis updated this revision to Diff 42607. eugenis marked an inline comment as done. Repository: rL LLVM http://reviews.llvm.org/D15367 Files: include/clang/Driver/Options.td include/clang/Driver/SanitizerArgs.h include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGVTables.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/MicrosoftCXXABI.cpp lib/Driver/SanitizerArgs.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/Driver/fsanitize.c test/Driver/sanitizer-ld.c Index: test/Driver/sanitizer-ld.c === --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -291,6 +291,46 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// CFI by itself does not link runtime libraries. +// RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-LINUX %s +// CHECK-CFI-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-LINUX-NOT: libclang_rt. + +// CFI with diagnostics links the UBSan runtime. +// RUN: %clang -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: %s -### -o %t.o 2>&1\ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s +// CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI links the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s +// CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI with diagnostics links just the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. + // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ // RUN: -target x86_64-apple-darwin13.4.0 \ Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -263,6 +263,15 @@ // CHECK-CFI-NOTRAP-WIN: -emit-llvm-bc // CHECK-CFI-NOTRAP-WIN-NOT: -fsanitize-trap=cfi +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -fno-sanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// CHECK-CFI-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-CROSS-DSO: -fsanitize-cfi-cross-dso +// CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- /dev/null +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis added inline comments. Comment at: lib/CodeGen/CGExpr.cpp:2558 @@ +2557,3 @@ + false)); + llvm::MDString *MDS = dyn_cast(MD); + llvm::Constant *TypeId = pcc wrote: > What happens if `MD` is not an `MDString`? assert + check on the caller side Repository: rL LLVM http://reviews.llvm.org/D15367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis updated this revision to Diff 42914. eugenis marked 10 inline comments as done. Repository: rL LLVM http://reviews.llvm.org/D15367 Files: docs/ControlFlowIntegrity.rst docs/ControlFlowIntegrityDesign.rst docs/UsersManual.rst include/clang/Driver/Options.td include/clang/Driver/SanitizerArgs.h include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGVTables.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/MicrosoftCXXABI.cpp lib/Driver/SanitizerArgs.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/Driver/fsanitize.c test/Driver/sanitizer-ld.c Index: test/Driver/sanitizer-ld.c === --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -291,6 +291,46 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// CFI by itself does not link runtime libraries. +// RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-LINUX %s +// CHECK-CFI-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-LINUX-NOT: libclang_rt. + +// CFI with diagnostics links the UBSan runtime. +// RUN: %clang -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: %s -### -o %t.o 2>&1\ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s +// CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI links the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s +// CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI with diagnostics links just the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. + // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ // RUN: -target x86_64-apple-darwin13.4.0 \ Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -263,6 +263,15 @@ // CHECK-CFI-NOTRAP-WIN: -emit-llvm-bc // CHECK-CFI-NOTRAP-WIN-NOT: -fsanitize-trap=cfi +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -fno-sanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// CHECK-CFI-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-CROSS-DSO: -fsanitize-cfi-cross-dso +// CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- /dev/null +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis added inline comments. Comment at: docs/ControlFlowIntegrityDesign.rst:389 @@ +388,3 @@ + - Calls between different instrumented DSOs are also protected with + performance penalty compared to the monolithic CFI. + - Calls from instrumented DSO to an uninstrumented one are unchecked pcc wrote: > "comparable" That changes the meaning of the sentence. I've changed the wording in a different way. Repository: rL LLVM http://reviews.llvm.org/D15367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis marked an inline comment as done. eugenis added a comment. Repository: rL LLVM http://reviews.llvm.org/D15367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r255712 - Relax checks in cfi-cross-dso test.
Author: eugenis Date: Tue Dec 15 17:49:51 2015 New Revision: 255712 URL: http://llvm.org/viewvc/llvm-project?rev=255712=rev Log: Relax checks in cfi-cross-dso test. The test is failing with unnamed labels. Modified: cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp Modified: cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp?rev=255712=255711=255712=diff == --- cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp (original) +++ cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp Tue Dec 15 17:49:51 2015 @@ -33,11 +33,11 @@ void g() { // ITANIUM: %[[TEST:.*]] = call i1 @llvm.bitset.test(i8* %[[VT2]], metadata !"_ZTS1A"), !nosanitize // MS: %[[TEST:.*]] = call i1 @llvm.bitset.test(i8* %[[VT2]], metadata !"?AUA@@"), !nosanitize // CHECK: br i1 %[[TEST]], label %[[CONT:.*]], label %[[SLOW:.*]], {{.*}} !nosanitize -// CHECK: [[SLOW]]: +// CHECK: [[SLOW]] // ITANIUM: call void @__cfi_slowpath(i64 7004155349499253778, i8* %[[VT2]]) {{.*}} !nosanitize // MS: call void @__cfi_slowpath(i64 -8005289897957287421, i8* %[[VT2]]) {{.*}} !nosanitize // CHECK: br label %[[CONT]], !nosanitize -// CHECK: [[CONT]]: +// CHECK: [[CONT]] // CHECK: call void %{{.*}}(%struct.A* %{{.*}}) // No hash-based bit set entry for (anonymous namespace)::B ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r255736 - [cfi] Exclude ubsan runtime library from non-diag CFI builds (driver changes).
Author: eugenis Date: Tue Dec 15 18:38:42 2015 New Revision: 255736 URL: http://llvm.org/viewvc/llvm-project?rev=255736=rev Log: [cfi] Exclude ubsan runtime library from non-diag CFI builds (driver changes). Split the CFI runtime in two: cfi and cfi_diag. The latter includes UBSan runtime to allow printing diagnostics. Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h cfe/trunk/lib/Driver/SanitizerArgs.cpp cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/sanitizer-ld.c Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=255736=255735=255736=diff == --- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original) +++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Tue Dec 15 18:38:42 2015 @@ -55,6 +55,7 @@ class SanitizerArgs { return Sanitizers.has(SanitizerKind::SafeStack); } bool needsCfiRt() const; + bool needsCfiDiagRt() const; bool requiresPIE() const; bool needsUnwindTables() const; Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=255736=255735=255736=diff == --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original) +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Dec 15 18:38:42 2015 @@ -165,7 +165,11 @@ bool SanitizerArgs::needsUbsanRt() const } bool SanitizerArgs::needsCfiRt() const { - return CfiCrossDso; + return !(Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso; +} + +bool SanitizerArgs::needsCfiDiagRt() const { + return (Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso; } bool SanitizerArgs::requiresPIE() const { Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=255736=255735=255736=diff == --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Tue Dec 15 18:38:42 2015 @@ -2794,6 +2794,8 @@ collectSanitizerRuntimes(const ToolChain StaticRuntimes.push_back("safestack"); if (SanArgs.needsCfiRt()) StaticRuntimes.push_back("cfi"); + if (SanArgs.needsCfiDiagRt()) +StaticRuntimes.push_back("cfi_diag"); } // Should be called before we add system libraries (C++ ABI, libstdc++/libc++, Modified: cfe/trunk/test/Driver/sanitizer-ld.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=255736=255735=255736=diff == --- cfe/trunk/test/Driver/sanitizer-ld.c (original) +++ cfe/trunk/test/Driver/sanitizer-ld.c Tue Dec 15 18:38:42 2015 @@ -317,7 +317,7 @@ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s // CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. -// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi- // CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. // Cross-DSO CFI with diagnostics links just the CFI runtime. @@ -328,7 +328,7 @@ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. -// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi_diag- // CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis updated this revision to Diff 42918. Repository: rL LLVM http://reviews.llvm.org/D15367 Files: docs/ControlFlowIntegrity.rst docs/ControlFlowIntegrityDesign.rst docs/UsersManual.rst include/clang/Driver/Options.td include/clang/Driver/SanitizerArgs.h include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGVTables.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/MicrosoftCXXABI.cpp lib/Driver/SanitizerArgs.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/Driver/fsanitize.c test/Driver/sanitizer-ld.c Index: test/Driver/sanitizer-ld.c === --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -291,6 +291,46 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// CFI by itself does not link runtime libraries. +// RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-LINUX %s +// CHECK-CFI-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-LINUX-NOT: libclang_rt. + +// CFI with diagnostics links the UBSan runtime. +// RUN: %clang -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: %s -### -o %t.o 2>&1\ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s +// CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI links the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s +// CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI with diagnostics links just the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. + // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ // RUN: -target x86_64-apple-darwin13.4.0 \ Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -263,6 +263,15 @@ // CHECK-CFI-NOTRAP-WIN: -emit-llvm-bc // CHECK-CFI-NOTRAP-WIN-NOT: -fsanitize-trap=cfi +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -fno-sanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// CHECK-CFI-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-CROSS-DSO: -fsanitize-cfi-cross-dso +// CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- /dev/null +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso
r255694 - Cross-DSO control flow integrity (Clang part).
Author: eugenis Date: Tue Dec 15 17:00:20 2015 New Revision: 255694 URL: http://llvm.org/viewvc/llvm-project?rev=255694=rev Log: Cross-DSO control flow integrity (Clang part). Clang-side cross-DSO CFI. * Adds a command line flag -f[no-]sanitize-cfi-cross-dso. * Links a runtime library when enabled. * Emits __cfi_slowpath calls is bitset test fails. * Emits extra hash-based bitsets for external CFI checks. * Sets a module flag to enable __cfi_check generation during LTO. This mode does not yet support diagnostics. Added: cfe/trunk/test/CodeGen/cfi-icall-cross-dso.c cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp Modified: cfe/trunk/docs/ControlFlowIntegrity.rst cfe/trunk/docs/ControlFlowIntegrityDesign.rst cfe/trunk/docs/UsersManual.rst cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/Driver/SanitizerArgs.h cfe/trunk/include/clang/Frontend/CodeGenOptions.def cfe/trunk/lib/CodeGen/CGClass.cpp cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/lib/CodeGen/CGVTables.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/CodeGen/CodeGenModule.h cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp cfe/trunk/lib/Driver/SanitizerArgs.cpp cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/Driver/fsanitize.c cfe/trunk/test/Driver/sanitizer-ld.c Modified: cfe/trunk/docs/ControlFlowIntegrity.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrity.rst?rev=255694=255693=255694=diff == --- cfe/trunk/docs/ControlFlowIntegrity.rst (original) +++ cfe/trunk/docs/ControlFlowIntegrity.rst Tue Dec 15 17:00:20 2015 @@ -24,10 +24,14 @@ You can also enable a subset of availabl As currently implemented, all schemes rely on link-time optimization (LTO); so it is required to specify ``-flto``, and the linker used must support LTO, for example via the `gold plugin`_. -To allow the checks to be implemented efficiently, the program must -be structured such that certain object files are compiled with CFI enabled, -and are statically linked into the program. This may preclude the use of -shared libraries in some cases. + +To allow the checks to be implemented efficiently, the program must be +structured such that certain object files are compiled with CFI +enabled, and are statically linked into the program. This may preclude +the use of shared libraries in some cases. Experimental support for +:ref:`cross-DSO control flow integrity ` exists that +does not have these requirements. This cross-DSO support has unstable +ABI at this time. .. _gold plugin: http://llvm.org/docs/GoldPlugin.html @@ -245,6 +249,16 @@ are typically defined outside of the lin # Ignore all types with a uuid attribute. type:attr:uuid +.. _cfi-cross-dso: + +Shared library support +== + +Use **-f[no-]sanitize-cfi-cross-dso** to enable the cross-DSO control +flow integrity mode, which allows all CFI schemes listed above to +apply across DSO boundaries. As in the regular CFI, each DSO must be +built with ``-flto``. + Design == Modified: cfe/trunk/docs/ControlFlowIntegrityDesign.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrityDesign.rst?rev=255694=255693=255694=diff == --- cfe/trunk/docs/ControlFlowIntegrityDesign.rst (original) +++ cfe/trunk/docs/ControlFlowIntegrityDesign.rst Tue Dec 15 17:00:20 2015 @@ -366,3 +366,134 @@ Because the addresses of ``f``, ``g``, ` we can normally apply the `Alignment`_ and `Eliminating Bit Vector Checks for All-Ones Bit Vectors`_ optimizations thus simplifying the check at each call site to a range and alignment check. + +Shared library support +== + +**EXPERIMENTAL** + +The basic CFI mode described above assumes that the application is a +monolithic binary; at least that all possible virtual/indirect call +targets and the entire class hierarchy are known at link time. The +cross-DSO mode, enabled with **-f[no-]sanitize-cfi-cross-dso** relaxes +this requirement by allowing virtual and indirect calls to cross the +DSO boundary. + +Assuming the following setup: the binary consists of several +instrumented and several uninstrumented DSOs. Some of them may be +dlopen-ed/dlclose-d periodically, even frequently. + + - Calls made from uninstrumented DSOs are not checked and just work. + - Calls inside any instrumented DSO are fully protected. + - Calls between different instrumented DSOs are also protected, with + a performance penalty (in addition to the monolithic CFI + overhead). + - Calls from an instrumented DSO to an uninstrumented one are + unchecked and just work, with performance penalty. + - Calls from an instrumented DSO outside of any known DSO are + detected as CFI
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis closed this revision. eugenis added a comment. r255694 Repository: rL LLVM http://reviews.llvm.org/D15367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14411: Use __attribute__((internal_linkage)) when available.
eugenis added a comment. With http://reviews.llvm.org/D15434, there is no difference in libc++ export list with the switch to internal_linkage. Repository: rL LLVM http://reviews.llvm.org/D14411 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15433: [libcxx] Remove inline/visibility attributes from exported template methods in valarray.
eugenis added a comment. Libc++.so does not instantiate valarray for any other types, so this does not add any extra exports. Definitions valarray members (with types other than size_t) will now be exported from user code. This looks like a positive change to me: - these methods are already part of the ABI due to the exported template valarray - exported vs hidden/internal can produce smaller code Repository: rL LLVM http://reviews.llvm.org/D15433 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis updated this revision to Diff 42782. eugenis marked 3 inline comments as done. Repository: rL LLVM http://reviews.llvm.org/D15367 Files: include/clang/Driver/Options.td include/clang/Driver/SanitizerArgs.h include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGVTables.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/MicrosoftCXXABI.cpp lib/Driver/SanitizerArgs.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/Driver/fsanitize.c test/Driver/sanitizer-ld.c Index: test/Driver/sanitizer-ld.c === --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -291,6 +291,46 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// CFI by itself does not link runtime libraries. +// RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-LINUX %s +// CHECK-CFI-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-LINUX-NOT: libclang_rt. + +// CFI with diagnostics links the UBSan runtime. +// RUN: %clang -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: %s -### -o %t.o 2>&1\ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s +// CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI links the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s +// CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI with diagnostics links just the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. + // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ // RUN: -target x86_64-apple-darwin13.4.0 \ Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -263,6 +263,15 @@ // CHECK-CFI-NOTRAP-WIN: -emit-llvm-bc // CHECK-CFI-NOTRAP-WIN-NOT: -fsanitize-trap=cfi +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -fno-sanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// CHECK-CFI-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-CROSS-DSO: -fsanitize-cfi-cross-dso +// CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- /dev/null +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis added inline comments. Comment at: lib/CodeGen/CGExpr.cpp:3871 @@ +3870,3 @@ +isa(MD) && dyn_cast(MD)->isDistinct(); +if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && !hasLocalScope) { + EmitCfiSlowPathCheck(BitSetTest, MD, CastedCallee); pcc wrote: > Early return. It's too early to return. Comment at: lib/CodeGen/CodeGenModule.cpp:996 @@ +995,3 @@ + !(isa(FD) && !cast(FD)->isStatic()) && + !(CodeGenOpts.SanitizeCfiCrossDso && !FD->hasBody() && +!(getContext().GetGVALinkageForFunction(FD) == pcc wrote: > This is a little hard to read and probably needs to go back into a function > with early returns. Sorry, my bad. I also think the logic for > `available_externally` is wrong (please add a test case). Moved out to a function. Added a testcase. Looks like available_externally is handled correctly. Repository: rL LLVM http://reviews.llvm.org/D15367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15367: Cross-DSO control flow integrity (Clang part)
eugenis updated this revision to Diff 42902. eugenis added a comment. added the new flag to UserManual Repository: rL LLVM http://reviews.llvm.org/D15367 Files: docs/ControlFlowIntegrity.rst docs/ControlFlowIntegrityDesign.rst docs/UsersManual.rst include/clang/Driver/Options.td include/clang/Driver/SanitizerArgs.h include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGVTables.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/CodeGen/MicrosoftCXXABI.cpp lib/Driver/SanitizerArgs.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/Driver/fsanitize.c test/Driver/sanitizer-ld.c Index: test/Driver/sanitizer-ld.c === --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -291,6 +291,46 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// CFI by itself does not link runtime libraries. +// RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-LINUX %s +// CHECK-CFI-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-LINUX-NOT: libclang_rt. + +// CFI with diagnostics links the UBSan runtime. +// RUN: %clang -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: %s -### -o %t.o 2>&1\ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-DIAG-LINUX %s +// CHECK-CFI-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-DIAG-LINUX: libclang_rt.ubsan +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI links the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s +// CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. + +// Cross-DSO CFI with diagnostics links just the CFI runtime. +// RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ +// RUN: -fno-sanitize-trap=cfi -fsanitize-recover=cfi \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. + // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ // RUN: -target x86_64-apple-darwin13.4.0 \ Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -263,6 +263,15 @@ // CHECK-CFI-NOTRAP-WIN: -emit-llvm-bc // CHECK-CFI-NOTRAP-WIN-NOT: -fsanitize-trap=cfi +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-cfi-cross-dso -fno-sanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NO-CROSS-DSO +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO +// CHECK-CFI-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-CROSS-DSO: -fsanitize-cfi-cross-dso +// CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc +// CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- /dev/null +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s +// RUN: %clang_cc1 -triple
[libcxx] r257193 - Revert "Remove visibility attributes from out-of-class method definitions in iostreams."
Author: eugenis Date: Fri Jan 8 13:21:02 2016 New Revision: 257193 URL: http://llvm.org/viewvc/llvm-project?rev=257193=rev Log: Revert "Remove visibility attributes from out-of-class method definitions in iostreams." Modified: libcxx/trunk/include/istream libcxx/trunk/include/ostream libcxx/trunk/include/sstream libcxx/trunk/include/streambuf Modified: libcxx/trunk/include/istream URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/istream?rev=257193=257192=257193=diff == --- libcxx/trunk/include/istream (original) +++ libcxx/trunk/include/istream Fri Jan 8 13:21:02 2016 @@ -304,7 +304,7 @@ basic_istream<_CharT, _Traits>::sentry:: } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf* __sb) : __gc_(0) { @@ -314,7 +314,7 @@ basic_istream<_CharT, _Traits>::basic_is #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) : __gc_(__rhs.__gc_) { @@ -323,7 +323,7 @@ basic_istream<_CharT, _Traits>::basic_is } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) { @@ -339,7 +339,7 @@ basic_istream<_CharT, _Traits>::~basic_i } template -inline +inline _LIBCPP_INLINE_VISIBILITY void basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs) { @@ -725,7 +725,7 @@ basic_istream<_CharT, _Traits>::operator } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&)) { @@ -733,7 +733,7 @@ basic_istream<_CharT, _Traits>::operator } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(basic_ios & (*__pf)(basic_ios &)) @@ -743,7 +743,7 @@ basic_istream<_CharT, _Traits>::operator } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&)) { @@ -800,7 +800,7 @@ operator>>(basic_istream<_CharT, _Traits } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream & operator>>(basic_istream & __is, unsigned char* __s) { @@ -808,7 +808,7 @@ operator>>(basic_istream & } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream & operator>>(basic_istream & __is, signed char* __s) { @@ -843,7 +843,7 @@ operator>>(basic_istream<_CharT, _Traits } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream & operator>>(basic_istream & __is, unsigned char& __c) { @@ -851,7 +851,7 @@ operator>>(basic_istream & } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream & operator>>(basic_istream & __is, signed char& __c) { @@ -947,7 +947,7 @@ basic_istream<_CharT, _Traits>::get() } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type& __c) { @@ -1006,7 +1006,7 @@ basic_istream<_CharT, _Traits>::get(char } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n) { @@ -1068,7 +1068,7 @@ basic_istream<_CharT, _Traits>::get(basi } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(basic_streambuf & __sb) { @@ -1129,7 +1129,7 @@ basic_istream<_CharT, _Traits>::getline( } template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n) { @@ -1462,7 +1462,7 @@ ws(basic_istream<_CharT, _Traits>& __is) #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) { @@ -1504,7 +1504,7 @@ public: }; template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf * __sb) : basic_istream<_CharT, _Traits>(__sb) { @@ -1513,14 +1513,14 @@ basic_iostream<_CharT, _Traits>::basic_i #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline +inline _LIBCPP_INLINE_VISIBILITY basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) { } template -inline +inline _LIBCPP_INLINE_VISIBILITY
[PATCH] D15699: [cfi] Cross-DSO CFI diagnostic mode (clang part)
eugenis created this revision. eugenis added reviewers: pcc, kcc. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. - Runtime diagnostic data for cfi-icall changed to match the rest of cfi checks - Layout of all CFI diagnostic data changed to put Kind at the beginning. There is no ABI stability promise yet. - call __cfi_slowpath_diag instead of __cfi_slowpath when needed. - emit __cfi_check_fail function, which dispatches a CFI check faliure according to trap/recover settings of the current module. - a tiny driver change to match the way the new handlers are done in compiler-rt. Repository: rL LLVM http://reviews.llvm.org/D15699 Files: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/Driver/Tools.cpp test/CodeGen/cfi-check-fail.c test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/CodeGenCXX/cfi-vcall.cpp Index: test/CodeGenCXX/cfi-vcall.cpp === --- test/CodeGenCXX/cfi-vcall.cpp +++ test/CodeGenCXX/cfi-vcall.cpp @@ -55,7 +55,7 @@ // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}cfi-vcall.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } -// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8 } { { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]], i8 0 } +// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } // ITANIUM: define void @_Z2afP1A // MS: define void @"\01?af@@YAXPEAUA@@@Z" @@ -69,9 +69,9 @@ // NDIAG-NEXT: call void @llvm.trap() // NDIAG-NEXT: unreachable // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint i8* [[VT]] to i64 - // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_bad_type_abort(i8* bitcast ({{.*}} @[[BADTYPESTATIC]] to i8*), i64 [[VTINT]]) + // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) // DIAG-ABORT-NEXT: unreachable - // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_bad_type(i8* bitcast ({{.*}} @[[BADTYPESTATIC]] to i8*), i64 [[VTINT]]) + // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) // DIAG-RECOVER-NEXT: br label %[[CONTBB]] // CHECK: [[CONTBB]] Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- test/CodeGenCXX/cfi-cross-dso.cpp +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -34,8 +34,8 @@ // MS: %[[TEST:.*]] = call i1 @llvm.bitset.test(i8* %[[VT2]], metadata !"?AUA@@"), !nosanitize // CHECK: br i1 %[[TEST]], label %[[CONT:.*]], label %[[SLOW:.*]], {{.*}} !nosanitize // CHECK: [[SLOW]] -// ITANIUM: call void @__cfi_slowpath(i64 7004155349499253778, i8* %[[VT2]]) {{.*}} !nosanitize -// MS: call void @__cfi_slowpath(i64 -8005289897957287421, i8* %[[VT2]]) {{.*}} !nosanitize +// ITANIUM: call void @__cfi_slowpath_diag(i64 7004155349499253778, i8* %[[VT2]], {{.*}}) {{.*}} !nosanitize +// MS: call void @__cfi_slowpath_diag(i64 -8005289897957287421, i8* %[[VT2]], {{.*}}) {{.*}} !nosanitize // CHECK: br label %[[CONT]], !nosanitize // CHECK: [[CONT]] // CHECK: call void %{{.*}}(%struct.A* %{{.*}}) Index: test/CodeGen/cfi-icall-cross-dso.c === --- test/CodeGen/cfi-icall-cross-dso.c +++ test/CodeGen/cfi-icall-cross-dso.c @@ -19,11 +19,16 @@ inline void foo() {} void bar() { foo(); } +// CHECK: @[[SRC:.*]] = private unnamed_addr constant {{.*}}cfi-icall-cross-dso.c\00 +// CHECK: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [{{.*}} x i8] } { i16 -1, i16 0, [{{.*}} x i8] c"'void ()'\00" +// CHECK: @[[DATA:.*]] = private unnamed_addr global {{.*}}@[[SRC]]{{.*}}@[[TYPE]] + + // ITANIUM: call i1 @llvm.bitset.test(i8* %{{.*}}, metadata !"_ZTSFvE"), !nosanitize -// ITANIUM: call void @__cfi_slowpath(i64 6588678392271548388, i8* %{{.*}}) {{.*}}, !nosanitize +// ITANIUM: call void @__cfi_slowpath_diag(i64 6588678392271548388, i8* %{{.*}}, {{.*}}@[[DATA]]{{.*}}, !nosanitize // MS: call i1 @llvm.bitset.test(i8* %{{.*}}, metadata !"?6AX@Z"), !nosanitize -// MS: call void @__cfi_slowpath(i64 4195979634929632483, i8* %{{.*}}) {{.*}}, !nosanitize +// MS: call void @__cfi_slowpath_diag(i64 4195979634929632483, i8* %{{.*}}, {{.*}}@[[DATA]]{{.*}}, !nosanitize // ITANIUM: define available_externally void @foo() // MS: define linkonce_odr void @foo() Index:
Re: [PATCH] D14409: Remove visibility attributes from out-of-class method definitions in iostreams.
eugenis added a comment. ping Repository: rL LLVM http://reviews.llvm.org/D14409 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14858: Support building tsan on android.
eugenis added a comment. I vaguely recall that android runtime loader had some symbol lookup differencies with glibc and that prevented interceptors (when statically linked into the main executable) from working. Maybe it is not the case now. http://reviews.llvm.org/D14858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14858: Support building tsan on android.
eugenis added a comment. In http://reviews.llvm.org/D14858#293651, @danalbert wrote: > I assume we're going to actually want to go the other direction on this and > build a shared library for Android's TSAN (see eugenis' comment on > https://android-review.googlesource.com/#/c/120507/1/core/config_sanitizers.mk@68) Yes, we should use shared runtime library on Android. See AsanSharedRuntime in SanitizerArgs.h, we need something similar for TSan. http://reviews.llvm.org/D14858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14858: Support building tsan on android.
eugenis added a comment. OK, it sounds like static runtime would work fine. We would still need a way to switch to the shared runtime for the apps (the workflow when we LD_PRELOAD the runtime into the Zygote to run instrumented apps on a non-instrumented device). Something like -shared-libasan flag but for TSan. Does not have to be done now. LGTM http://reviews.llvm.org/D14858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19854: Define Contiki OS toolchain
eugenis accepted this revision. eugenis added a comment. This revision is now accepted and ready to land. LGTM http://reviews.llvm.org/D19854 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21054: CodeGen: Update Clang to use the new type metadata.
eugenis accepted this revision. eugenis added a reviewer: eugenis. eugenis added a comment. This revision is now accepted and ready to land. LGTM http://reviews.llvm.org/D21054 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19854: Define Contiki OS toolchain
eugenis added a comment. This needs a driver test. http://reviews.llvm.org/D19854 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21317: [sanitizer] Allow sanitize coverage w/o sanitizers.
eugenis added a comment. ubsan_standalone (that's what the needsUbsanRt change is for). Repository: rL LLVM http://reviews.llvm.org/D21317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21317: [sanitizer] Allow sanitize coverage w/o sanitizers.
eugenis added a comment. In http://reviews.llvm.org/D21317#457784, @kcc wrote: > Can you at least add a compiler-rt test where we ensure that this flag can > not be used such that it wil compile but fail to link? > > E.g. > > clang -fsanitize-coverage=edge x.c > > should compile *and* link (and run) http://reviews.llvm.org/D21339 Repository: rL LLVM http://reviews.llvm.org/D21317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D20561: Warn when taking address of packed member
eugenis added a subscriber: eugenis. eugenis added a comment. In http://reviews.llvm.org/D20561#446031, @aaron.ballman wrote: > In http://reviews.llvm.org/D20561#445824, @rogfer01 wrote: > > > I think I wasn't clear with the purpose of the fix-it: there are a few > > cases where getting the address of an unaligned pointer is safe (i.e. false > > positives). > > > > For instance, when I checked Firefox and Chromium there are cases where > > getting the address of an unaligned pointer is fine. For the particular > > case of these two browsers, they both use a library (usrsctp) that > > represents protocol data as packed structs. That library passes addresses > > of packed fields to `memcpy` and `memmove` which is OK. > > > I think this is a false-positive that should be fixed. This patch was committed without fixing the false positive case, why? Could this warning be excluded from -Wall? Repository: rL LLVM http://reviews.llvm.org/D20561 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21317: [sanitizer] Allow sanitize coverage w/o sanitizers.
eugenis added a comment. For the context, this is supposed to fix this problem: https://bugs.chromium.org/p/chromium/issues/detail?id=618534 Of course there are other ways of dealing with that that do not require changing the compiler, but this change seems like the right thing to do. The limitation on the standalone use of coverage seems arbitrary. Repository: rL LLVM http://reviews.llvm.org/D21317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D21317: [sanitizer] Allow sanitize coverage w/o sanitizers.
eugenis created this revision. eugenis added reviewers: pcc, kcc. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. The reason is that this (a) seems to work just fine and (b) is useful when building stuff with sanitizer+coverage, but needing to exclude the sanitizer for a particular source file. Repository: rL LLVM http://reviews.llvm.org/D21317 Files: lib/Driver/SanitizerArgs.cpp test/Driver/fsanitize-coverage.c Index: test/Driver/fsanitize-coverage.c === --- test/Driver/fsanitize-coverage.c +++ test/Driver/fsanitize-coverage.c @@ -33,7 +33,7 @@ // CHECK-SANITIZE-COVERAGE-5: error: unsupported argument '5' to option 'fsanitize-coverage=' // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED -// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC // CHECK-SANITIZE-COVERAGE-UNUSED: argument unused during compilation: '-fsanitize-coverage=func' // CHECK-SANITIZE-COVERAGE-UNUSED-NOT: -fsanitize-coverage-type=1 Index: lib/Driver/SanitizerArgs.cpp === --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -159,11 +159,10 @@ } bool SanitizerArgs::needsUbsanRt() const { - return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) && - !Sanitizers.has(Address) && - !Sanitizers.has(Memory) && - !Sanitizers.has(Thread) && - !CfiCrossDso; + return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) || + CoverageFeatures) && + !Sanitizers.has(Address) && !Sanitizers.has(Memory) && + !Sanitizers.has(Thread) && !CfiCrossDso; } bool SanitizerArgs::needsCfiRt() const { @@ -485,10 +484,10 @@ continue; } CoverageFeatures |= parseCoverageFeatures(D, Arg); - // If there is trace-pc, allow it w/o any of the sanitizers. - // Otherwise, require that one of the supported sanitizers is present. - if ((CoverageFeatures & CoverageTracePC) || - (AllAddedKinds & SupportsCoverage)) { + + // Disable coverage and not claim the flags if there is at least one + // non-supporting sanitizer. + if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) { Arg->claim(); } else { CoverageFeatures = 0; Index: test/Driver/fsanitize-coverage.c === --- test/Driver/fsanitize-coverage.c +++ test/Driver/fsanitize-coverage.c @@ -33,7 +33,7 @@ // CHECK-SANITIZE-COVERAGE-5: error: unsupported argument '5' to option 'fsanitize-coverage=' // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED -// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC // CHECK-SANITIZE-COVERAGE-UNUSED: argument unused during compilation: '-fsanitize-coverage=func' // CHECK-SANITIZE-COVERAGE-UNUSED-NOT: -fsanitize-coverage-type=1 Index: lib/Driver/SanitizerArgs.cpp === --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -159,11 +159,10 @@ } bool SanitizerArgs::needsUbsanRt() const { - return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) && - !Sanitizers.has(Address) && - !Sanitizers.has(Memory) && - !Sanitizers.has(Thread) && - !CfiCrossDso; + return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) || + CoverageFeatures) && + !Sanitizers.has(Address) && !Sanitizers.has(Memory) && + !Sanitizers.has(Thread) && !CfiCrossDso; } bool SanitizerArgs::needsCfiRt() const { @@ -485,10 +484,10 @@ continue; } CoverageFeatures |= parseCoverageFeatures(D, Arg); - // If there is trace-pc, allow it w/o any of the sanitizers. - // Otherwise, require that one of the supported sanitizers is present. - if ((CoverageFeatures & CoverageTracePC) || - (AllAddedKinds & SupportsCoverage)) { + + // Disable coverage and not claim the flags if there is at least one + // non-supporting sanitizer. + if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) { Arg->claim(); } else { CoverageFeatures
Re: [PATCH] D21317: [sanitizer] Allow sanitize coverage w/o sanitizers.
eugenis updated this revision to Diff 60759. eugenis added a comment. + docs Repository: rL LLVM http://reviews.llvm.org/D21317 Files: docs/SanitizerCoverage.rst lib/Driver/SanitizerArgs.cpp test/Driver/fsanitize-coverage.c Index: test/Driver/fsanitize-coverage.c === --- test/Driver/fsanitize-coverage.c +++ test/Driver/fsanitize-coverage.c @@ -33,7 +33,7 @@ // CHECK-SANITIZE-COVERAGE-5: error: unsupported argument '5' to option 'fsanitize-coverage=' // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED -// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC // CHECK-SANITIZE-COVERAGE-UNUSED: argument unused during compilation: '-fsanitize-coverage=func' // CHECK-SANITIZE-COVERAGE-UNUSED-NOT: -fsanitize-coverage-type=1 Index: lib/Driver/SanitizerArgs.cpp === --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -159,11 +159,10 @@ } bool SanitizerArgs::needsUbsanRt() const { - return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) && - !Sanitizers.has(Address) && - !Sanitizers.has(Memory) && - !Sanitizers.has(Thread) && - !CfiCrossDso; + return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) || + CoverageFeatures) && + !Sanitizers.has(Address) && !Sanitizers.has(Memory) && + !Sanitizers.has(Thread) && !CfiCrossDso; } bool SanitizerArgs::needsCfiRt() const { @@ -485,10 +484,10 @@ continue; } CoverageFeatures |= parseCoverageFeatures(D, Arg); - // If there is trace-pc, allow it w/o any of the sanitizers. - // Otherwise, require that one of the supported sanitizers is present. - if ((CoverageFeatures & CoverageTracePC) || - (AllAddedKinds & SupportsCoverage)) { + + // Disable coverage and not claim the flags if there is at least one + // non-supporting sanitizer. + if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) { Arg->claim(); } else { CoverageFeatures = 0; Index: docs/SanitizerCoverage.rst === --- docs/SanitizerCoverage.rst +++ docs/SanitizerCoverage.rst @@ -16,8 +16,9 @@ SanitizerCoverage can be used with :doc:`AddressSanitizer`, -:doc:`LeakSanitizer`, :doc:`MemorySanitizer`, and UndefinedBehaviorSanitizer. -In addition to ``-fsanitize=``, pass one of the following compile-time flags: +:doc:`LeakSanitizer`, :doc:`MemorySanitizer`, +UndefinedBehaviorSanitizer, or without any sanitizer. Pass one of the +following compile-time flags: * ``-fsanitize-coverage=func`` for function-level coverage (very fast). * ``-fsanitize-coverage=bb`` for basic-block-level coverage (may add up to 30% @@ -27,8 +28,9 @@ You may also specify ``-fsanitize-coverage=indirect-calls`` for additional `caller-callee coverage`_. -At run time, pass ``coverage=1`` in ``ASAN_OPTIONS``, ``LSAN_OPTIONS``, -``MSAN_OPTIONS`` or ``UBSAN_OPTIONS``, as appropriate. +At run time, pass ``coverage=1`` in ``ASAN_OPTIONS``, +``LSAN_OPTIONS``, ``MSAN_OPTIONS`` or ``UBSAN_OPTIONS``, as +appropriate. For the standalone coverage mode, use ``UBSAN_OPTIONS``. To get `Coverage counters`_, add ``-fsanitize-coverage=8bit-counters`` to one of the above compile-time flags. At runtime, use Index: test/Driver/fsanitize-coverage.c === --- test/Driver/fsanitize-coverage.c +++ test/Driver/fsanitize-coverage.c @@ -33,7 +33,7 @@ // CHECK-SANITIZE-COVERAGE-5: error: unsupported argument '5' to option 'fsanitize-coverage=' // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED -// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC // CHECK-SANITIZE-COVERAGE-UNUSED: argument unused during compilation: '-fsanitize-coverage=func' // CHECK-SANITIZE-COVERAGE-UNUSED-NOT: -fsanitize-coverage-type=1 Index: lib/Driver/SanitizerArgs.cpp === --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -159,11 +159,10 @@ } bool SanitizerArgs::needsUbsanRt() const { -
r272717 - [sanitizer] Allow sanitize coverage w/o sanitizers.
Author: eugenis Date: Tue Jun 14 16:33:40 2016 New Revision: 272717 URL: http://llvm.org/viewvc/llvm-project?rev=272717=rev Log: [sanitizer] Allow sanitize coverage w/o sanitizers. The reason is that this (a) seems to work just fine and (b) useful when building stuff with sanitizer+coverage, but need to exclude the sanitizer for a particular source file. Modified: cfe/trunk/docs/SanitizerCoverage.rst cfe/trunk/lib/Driver/SanitizerArgs.cpp cfe/trunk/test/Driver/fsanitize-coverage.c Modified: cfe/trunk/docs/SanitizerCoverage.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SanitizerCoverage.rst?rev=272717=272716=272717=diff == --- cfe/trunk/docs/SanitizerCoverage.rst (original) +++ cfe/trunk/docs/SanitizerCoverage.rst Tue Jun 14 16:33:40 2016 @@ -16,8 +16,9 @@ How to build and run SanitizerCoverage can be used with :doc:`AddressSanitizer`, -:doc:`LeakSanitizer`, :doc:`MemorySanitizer`, and UndefinedBehaviorSanitizer. -In addition to ``-fsanitize=``, pass one of the following compile-time flags: +:doc:`LeakSanitizer`, :doc:`MemorySanitizer`, +UndefinedBehaviorSanitizer, or without any sanitizer. Pass one of the +following compile-time flags: * ``-fsanitize-coverage=func`` for function-level coverage (very fast). * ``-fsanitize-coverage=bb`` for basic-block-level coverage (may add up to 30% @@ -27,8 +28,9 @@ In addition to ``-fsanitize=``, pass one You may also specify ``-fsanitize-coverage=indirect-calls`` for additional `caller-callee coverage`_. -At run time, pass ``coverage=1`` in ``ASAN_OPTIONS``, ``LSAN_OPTIONS``, -``MSAN_OPTIONS`` or ``UBSAN_OPTIONS``, as appropriate. +At run time, pass ``coverage=1`` in ``ASAN_OPTIONS``, +``LSAN_OPTIONS``, ``MSAN_OPTIONS`` or ``UBSAN_OPTIONS``, as +appropriate. For the standalone coverage mode, use ``UBSAN_OPTIONS``. To get `Coverage counters`_, add ``-fsanitize-coverage=8bit-counters`` to one of the above compile-time flags. At runtime, use Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=272717=272716=272717=diff == --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original) +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Jun 14 16:33:40 2016 @@ -159,11 +159,10 @@ static SanitizerMask parseSanitizeTrapAr } bool SanitizerArgs::needsUbsanRt() const { - return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) && - !Sanitizers.has(Address) && - !Sanitizers.has(Memory) && - !Sanitizers.has(Thread) && - !CfiCrossDso; + return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) || + CoverageFeatures) && + !Sanitizers.has(Address) && !Sanitizers.has(Memory) && + !Sanitizers.has(Thread) && !CfiCrossDso; } bool SanitizerArgs::needsCfiRt() const { @@ -485,10 +484,10 @@ SanitizerArgs::SanitizerArgs(const ToolC continue; } CoverageFeatures |= parseCoverageFeatures(D, Arg); - // If there is trace-pc, allow it w/o any of the sanitizers. - // Otherwise, require that one of the supported sanitizers is present. - if ((CoverageFeatures & CoverageTracePC) || - (AllAddedKinds & SupportsCoverage)) { + + // Disable coverage and not claim the flags if there is at least one + // non-supporting sanitizer. + if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) { Arg->claim(); } else { CoverageFeatures = 0; Modified: cfe/trunk/test/Driver/fsanitize-coverage.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-coverage.c?rev=272717=272716=272717=diff == --- cfe/trunk/test/Driver/fsanitize-coverage.c (original) +++ cfe/trunk/test/Driver/fsanitize-coverage.c Tue Jun 14 16:33:40 2016 @@ -33,7 +33,7 @@ // CHECK-SANITIZE-COVERAGE-5: error: unsupported argument '5' to option 'fsanitize-coverage=' // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED -// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC // CHECK-SANITIZE-COVERAGE-UNUSED: argument unused during compilation: '-fsanitize-coverage=func' // CHECK-SANITIZE-COVERAGE-UNUSED-NOT: -fsanitize-coverage-type=1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r272735 - Fix sanitizer coverage support in the win32 driver.
Author: eugenis Date: Tue Jun 14 18:21:19 2016 New Revision: 272735 URL: http://llvm.org/viewvc/llvm-project?rev=272735=rev Log: Fix sanitizer coverage support in the win32 driver. --dependent-lib arguments for the sanitizer libraries must be emitted when coverage is enabled w/o any sanitizers. Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp cfe/trunk/test/Driver/fsanitize.c Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=272735=272734=272735=diff == --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original) +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Jun 14 18:21:19 2016 @@ -622,6 +622,28 @@ void SanitizerArgs::addArgs(const ToolCh CmdArgs.push_back(Args.MakeArgString(F.second)); } + if (TC.getTriple().isOSWindows() && needsUbsanRt()) { +// Instruct the code generator to embed linker directives in the object file +// that cause the required runtime libraries to be linked. +CmdArgs.push_back(Args.MakeArgString( +"--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone"))); +if (types::isCXX(InputType)) + CmdArgs.push_back(Args.MakeArgString( + "--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone_cxx"))); + } + if (TC.getTriple().isOSWindows() && needsStatsRt()) { +CmdArgs.push_back(Args.MakeArgString("--dependent-lib=" + + TC.getCompilerRT(Args, "stats_client"))); + +// The main executable must export the stats runtime. +// FIXME: Only exporting from the main executable (e.g. based on whether the +// translation unit defines main()) would save a little space, but having +// multiple copies of the runtime shouldn't hurt. +CmdArgs.push_back(Args.MakeArgString("--dependent-lib=" + + TC.getCompilerRT(Args, "stats"))); +addIncludeLinkerOption(TC, Args, CmdArgs, "__sanitizer_stats_register"); + } + if (Sanitizers.empty()) return; CmdArgs.push_back(Args.MakeArgString("-fsanitize=" + toString(Sanitizers))); @@ -673,28 +695,6 @@ void SanitizerArgs::addArgs(const ToolCh if (Sanitizers.has(Memory) || Sanitizers.has(Address)) CmdArgs.push_back(Args.MakeArgString("-fno-assume-sane-operator-new")); - if (TC.getTriple().isOSWindows() && needsUbsanRt()) { -// Instruct the code generator to embed linker directives in the object file -// that cause the required runtime libraries to be linked. -CmdArgs.push_back(Args.MakeArgString( -"--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone"))); -if (types::isCXX(InputType)) - CmdArgs.push_back(Args.MakeArgString( - "--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone_cxx"))); - } - if (TC.getTriple().isOSWindows() && needsStatsRt()) { -CmdArgs.push_back(Args.MakeArgString("--dependent-lib=" + - TC.getCompilerRT(Args, "stats_client"))); - -// The main executable must export the stats runtime. -// FIXME: Only exporting from the main executable (e.g. based on whether the -// translation unit defines main()) would save a little space, but having -// multiple copies of the runtime shouldn't hurt. -CmdArgs.push_back(Args.MakeArgString("--dependent-lib=" + - TC.getCompilerRT(Args, "stats"))); -addIncludeLinkerOption(TC, Args, CmdArgs, "__sanitizer_stats_register"); - } - // Require -fvisibility= flag on non-Windows when compiling if vptr CFI is // enabled. if (Sanitizers.hasOneOf(CFIClasses) && !TC.getTriple().isOSWindows() && Modified: cfe/trunk/test/Driver/fsanitize.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=272735=272734=272735=diff == --- cfe/trunk/test/Driver/fsanitize.c (original) +++ cfe/trunk/test/Driver/fsanitize.c Tue Jun 14 18:21:19 2016 @@ -20,10 +20,15 @@ // RUN: %clang -target i386-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN --check-prefix=CHECK-UNDEFINED-WIN32 --check-prefix=CHECK-UNDEFINED-WIN-CXX // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN --check-prefix=CHECK-UNDEFINED-WIN64 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN --check-prefix=CHECK-UNDEFINED-WIN64 --check-prefix=CHECK-UNDEFINED-WIN-CXX -// CHECK-UNDEFINED-WIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}} -//
Re: [PATCH] D21122: CodeGen: Start emitting checked loads when both trapping CFI and -fwhole-program-vtables are enabled.
eugenis accepted this revision. eugenis added a comment. This revision is now accepted and ready to land. LGTM http://reviews.llvm.org/D21122 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r272853 - Fix linking of DFSan + coverage.
Author: eugenis Date: Wed Jun 15 18:05:21 2016 New Revision: 272853 URL: http://llvm.org/viewvc/llvm-project?rev=272853=rev Log: Fix linking of DFSan + coverage. Broken in r272717 because of no test coverage. Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp cfe/trunk/test/Driver/sanitizer-ld.c Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=272853=272852=272853=diff == --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original) +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Wed Jun 15 18:05:21 2016 @@ -162,7 +162,7 @@ bool SanitizerArgs::needsUbsanRt() const return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) || CoverageFeatures) && !Sanitizers.has(Address) && !Sanitizers.has(Memory) && - !Sanitizers.has(Thread) && !CfiCrossDso; + !Sanitizers.has(Thread) && !Sanitizers.has(DataFlow) && !CfiCrossDso; } bool SanitizerArgs::needsCfiRt() const { Modified: cfe/trunk/test/Driver/sanitizer-ld.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=272853=272852=272853=diff == --- cfe/trunk/test/Driver/sanitizer-ld.c (original) +++ cfe/trunk/test/Driver/sanitizer-ld.c Wed Jun 15 18:05:21 2016 @@ -293,6 +293,61 @@ // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan +// RUN: %clang -fsanitize=address -fsanitize-coverage=func %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-ASAN-COV-LINUX %s +// CHECK-ASAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-ASAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.asan-x86_64.a" "-no-whole-archive" +// CHECK-ASAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.asan-x86_64.a.syms" +// CHECK-ASAN-COV-LINUX-NOT: libclang_rt.ubsan +// CHECK-ASAN-COV-LINUX-NOT: "-lstdc++" +// CHECK-ASAN-COV-LINUX: "-lpthread" + +// RUN: %clang -fsanitize=memory -fsanitize-coverage=func %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-MSAN-COV-LINUX %s +// CHECK-MSAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-MSAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.msan-x86_64.a" "-no-whole-archive" +// CHECK-MSAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.msan-x86_64.a.syms" +// CHECK-MSAN-COV-LINUX-NOT: libclang_rt.ubsan +// CHECK-MSAN-COV-LINUX-NOT: "-lstdc++" +// CHECK-MSAN-COV-LINUX: "-lpthread" + +// RUN: %clang -fsanitize=dataflow -fsanitize-coverage=func %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-DFSAN-COV-LINUX %s +// CHECK-DFSAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-DFSAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.dfsan-x86_64.a" "-no-whole-archive" +// CHECK-DFSAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.dfsan-x86_64.a.syms" +// CHECK-DFSAN-COV-LINUX-NOT: libclang_rt.ubsan +// CHECK-DFSAN-COV-LINUX-NOT: "-lstdc++" +// CHECK-DFSAN-COV-LINUX: "-lpthread" + +// RUN: %clang -fsanitize=undefined -fsanitize-coverage=func %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-UBSAN-COV-LINUX %s +// CHECK-UBSAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-UBSAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.ubsan_standalone-x86_64.a" "-no-whole-archive" +// CHECK-UBSAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.ubsan_standalone-x86_64.a.syms" +// CHECK-UBSAN-COV-LINUX-NOT: libclang_rt.ubsan +// CHECK-UBSAN-COV-LINUX-NOT: "-lstdc++" +// CHECK-UBSAN-COV-LINUX: "-lpthread" + +// RUN: %clang -fsanitize-coverage=func %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-COV-LINUX %s +// CHECK-COV-LINUX: "{{.*}}ld{{(.exe)?}}" +// CHECK-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.ubsan_standalone-x86_64.a" "-no-whole-archive" +// CHECK-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.ubsan_standalone-x86_64.a.syms" +// CHECK-COV-LINUX-NOT: libclang_rt.ubsan +// CHECK-COV-LINUX-NOT: "-lstdc++" +// CHECK-COV-LINUX: "-lpthread" + // CFI by itself does not link runtime libraries. // RUN: %clang -fsanitize=cfi %s -### -o %t.o 2>&1 \ // RUN: -target x86_64-unknown-linux \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r272856 - Fix sanitizer-ld test.
Author: eugenis Date: Wed Jun 15 18:29:26 2016 New Revision: 272856 URL: http://llvm.org/viewvc/llvm-project?rev=272856=rev Log: Fix sanitizer-ld test. Modified: cfe/trunk/test/Driver/sanitizer-ld.c Modified: cfe/trunk/test/Driver/sanitizer-ld.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=272856=272855=272856=diff == --- cfe/trunk/test/Driver/sanitizer-ld.c (original) +++ cfe/trunk/test/Driver/sanitizer-ld.c Wed Jun 15 18:29:26 2016 @@ -299,7 +299,6 @@ // RUN: | FileCheck --check-prefix=CHECK-ASAN-COV-LINUX %s // CHECK-ASAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-ASAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.asan-x86_64.a" "-no-whole-archive" -// CHECK-ASAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.asan-x86_64.a.syms" // CHECK-ASAN-COV-LINUX-NOT: libclang_rt.ubsan // CHECK-ASAN-COV-LINUX-NOT: "-lstdc++" // CHECK-ASAN-COV-LINUX: "-lpthread" @@ -310,7 +309,6 @@ // RUN: | FileCheck --check-prefix=CHECK-MSAN-COV-LINUX %s // CHECK-MSAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-MSAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.msan-x86_64.a" "-no-whole-archive" -// CHECK-MSAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.msan-x86_64.a.syms" // CHECK-MSAN-COV-LINUX-NOT: libclang_rt.ubsan // CHECK-MSAN-COV-LINUX-NOT: "-lstdc++" // CHECK-MSAN-COV-LINUX: "-lpthread" @@ -321,7 +319,6 @@ // RUN: | FileCheck --check-prefix=CHECK-DFSAN-COV-LINUX %s // CHECK-DFSAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-DFSAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.dfsan-x86_64.a" "-no-whole-archive" -// CHECK-DFSAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.dfsan-x86_64.a.syms" // CHECK-DFSAN-COV-LINUX-NOT: libclang_rt.ubsan // CHECK-DFSAN-COV-LINUX-NOT: "-lstdc++" // CHECK-DFSAN-COV-LINUX: "-lpthread" @@ -332,8 +329,6 @@ // RUN: | FileCheck --check-prefix=CHECK-UBSAN-COV-LINUX %s // CHECK-UBSAN-COV-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-UBSAN-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.ubsan_standalone-x86_64.a" "-no-whole-archive" -// CHECK-UBSAN-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.ubsan_standalone-x86_64.a.syms" -// CHECK-UBSAN-COV-LINUX-NOT: libclang_rt.ubsan // CHECK-UBSAN-COV-LINUX-NOT: "-lstdc++" // CHECK-UBSAN-COV-LINUX: "-lpthread" @@ -343,8 +338,6 @@ // RUN: | FileCheck --check-prefix=CHECK-COV-LINUX %s // CHECK-COV-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-COV-LINUX: "-whole-archive" "{{.*}}libclang_rt.ubsan_standalone-x86_64.a" "-no-whole-archive" -// CHECK-COV-LINUX: "--dynamic-list={{.*}}libclang_rt.ubsan_standalone-x86_64.a.syms" -// CHECK-COV-LINUX-NOT: libclang_rt.ubsan // CHECK-COV-LINUX-NOT: "-lstdc++" // CHECK-COV-LINUX: "-lpthread" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D20561: Warn when taking address of packed member
eugenis added a comment. This timeval thing looks like a legitimate warning to me. I don't think the analysis should go beyond the function boundaries. If a callee expects timeval * as part of its signature it should get a properly aligned timeval *. http://reviews.llvm.org/D20561 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21317: [sanitizer] Allow sanitize coverage w/o sanitizers.
eugenis closed this revision. eugenis added a comment. r272717 Repository: rL LLVM http://reviews.llvm.org/D21317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r260441 - Fix invalid casts in .
Author: eugenis Date: Wed Feb 10 15:53:28 2016 New Revision: 260441 URL: http://llvm.org/viewvc/llvm-project?rev=260441=rev Log: Fix invalid casts in . static_cast of a pointer to object before the start of the object's lifetime has undefined behavior. This code triggers CFI warnings. This change replaces C-style casts with reinterpret_cast, which is fine per the standard, add applies an attribute to silence CFI (which barks on reinterpret_cast, too). Modified: libcxx/trunk/include/__config libcxx/trunk/include/functional Modified: libcxx/trunk/include/__config URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=260441=260440=260441=diff == --- libcxx/trunk/include/__config (original) +++ libcxx/trunk/include/__config Wed Feb 10 15:53:28 2016 @@ -180,6 +180,12 @@ # endif #endif // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) +#if __has_attribute(__no_sanitize__) +#define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) +#else +#define _LIBCPP_NO_CFI +#endif + #ifdef _WIN32 // only really useful for a DLL Modified: libcxx/trunk/include/functional URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/functional?rev=260441=260440=260441=diff == --- libcxx/trunk/include/functional (original) +++ libcxx/trunk/include/functional Wed Feb 10 15:53:28 2016 @@ -1564,6 +1564,10 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp typename aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; +_LIBCPP_NO_CFI static __base *__as_base(void *p) { + return reinterpret_cast<__base*>(p); +} + template ::value && __invokable<_Fp&, _ArgTypes...>::value> struct __callable; @@ -1660,9 +1664,9 @@ function<_Rp(_ArgTypes...)>::function(co { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (const __base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1676,9 +1680,9 @@ function<_Rp(_ArgTypes...)>::function(al { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (const __base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1690,9 +1694,9 @@ function<_Rp(_ArgTypes...)>::function(fu { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1709,9 +1713,9 @@ function<_Rp(_ArgTypes...)>::function(al { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1736,8 +1740,7 @@ function<_Rp(_ArgTypes...)>::function(_F typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) { -__f_ = (__base*)&__buf_; -::new (__f_) _FF(_VSTD::move(__f)); +__f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); } else { @@ -1766,8 +1769,7 @@ function<_Rp(_ArgTypes...)>::function(al if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) { -__f_ = (__base*)&__buf_; -::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a)); +__f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); } else { @@ -1791,16 +1793,16 @@ template function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); __f_ = 0; if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1815,7 +1817,7 @@ template function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1840,7 +1842,7 @@ function<_Rp(_ArgTypes...)>::operator=(_
Re: [PATCH] D16738: Fix invalid casts in .
eugenis closed this revision. eugenis added a comment. Thanks for the review! Committed as r260441. Repository: rL LLVM http://reviews.llvm.org/D16738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16738: Fix invalid casts in .
eugenis added a comment. In http://reviews.llvm.org/D16738#345696, @EricWF wrote: > I prefer using the `(void*)` casts when possible. In particular when doing > the pointer comparisons. Could you change those back to `void*` casts then > use the `__as_base` function for the rest? done Repository: rL LLVM http://reviews.llvm.org/D16738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16738: Fix invalid casts in .
eugenis updated this revision to Diff 47271. Repository: rL LLVM http://reviews.llvm.org/D16738 Files: include/__config include/functional Index: include/functional === --- include/functional +++ include/functional @@ -1564,6 +1564,10 @@ typename aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; +_LIBCPP_NO_CFI static __base *__as_base(void *p) { + return reinterpret_cast<__base*>(p); +} + template ::value && __invokable<_Fp&, _ArgTypes...>::value> struct __callable; @@ -1660,9 +1664,9 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (const __base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1676,9 +1680,9 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (const __base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1690,9 +1694,9 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1709,9 +1713,9 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1736,8 +1740,7 @@ typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) { -__f_ = (__base*)&__buf_; -::new (__f_) _FF(_VSTD::move(__f)); +__f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); } else { @@ -1766,8 +1769,7 @@ if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) { -__f_ = (__base*)&__buf_; -::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a)); +__f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); } else { @@ -1791,16 +1793,16 @@ function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); __f_ = 0; if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1815,7 +1817,7 @@ function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1840,7 +1842,7 @@ template function<_Rp(_ArgTypes...)>::~function() { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1850,34 +1852,34 @@ void function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT { -if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) +if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) { typename aligned_storage::type __tempbuf; -__base* __t = (__base*)&__tempbuf; +__base* __t = __as_base(&__tempbuf); __f_->__clone(__t); __f_->destroy(); __f_ = 0; -__f.__f_->__clone((__base*)&__buf_); +__f.__f_->__clone(__as_base(&__buf_)); __f.__f_->destroy(); __f.__f_ = 0; -__f_ = (__base*)&__buf_; -__t->__clone((__base*)&__f.__buf_); +__f_ = __as_base(&__buf_); +__t->__clone(__as_base(&__f.__buf_)); __t->destroy(); -__f.__f_ = (__base*)&__f.__buf_; +__f.__f_ = __as_base(&__f.__buf_); } -else if (__f_ == (__base*)&__buf_) +else if ((void *)__f_ == &__buf_) { -__f_->__clone((__base*)&__f.__buf_); +__f_->__clone(__as_base(&__f.__buf_)); __f_->destroy(); __f_ = __f.__f_; -__f.__f_ = (__base*)&__f.__buf_; +__f.__f_ = __as_base(&__f.__buf_); } -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { -
r258997 - Strengthen cfi-check-fail test.
Author: eugenis Date: Wed Jan 27 16:28:56 2016 New Revision: 258997 URL: http://llvm.org/viewvc/llvm-project?rev=258997=rev Log: Strengthen cfi-check-fail test. r258993 allows stricter testing for basic block labels by making sure that they are always followed by ":". Use this to improve the test. Modified: cfe/trunk/test/CodeGen/cfi-check-fail.c Modified: cfe/trunk/test/CodeGen/cfi-check-fail.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail.c?rev=258997=258996=258997=diff == --- cfe/trunk/test/CodeGen/cfi-check-fail.c (original) +++ cfe/trunk/test/CodeGen/cfi-check-fail.c Wed Jan 27 16:28:56 2016 @@ -14,58 +14,58 @@ void caller(void (*f)()) { // CHECK: %[[ICMP_NOT_NULL:.*]] = icmp ne i8* %[[DATA]], null // CHECK: br i1 %[[ICMP_NOT_NULL]], label %[[CONT0:.*]], label %[[TRAP:.*]], -// CHECK: [[TRAP]] +// CHECK: [[TRAP]]: // CHECK-NEXT: call void @llvm.trap() // CHECK-NEXT: unreachable -// CHECK: [[CONT0]] +// CHECK: [[CONT0]]: // CHECK: %[[A:.*]] = bitcast i8* %[[DATA]] to { i8, { i8*, i32, i32 }, i8* }* // CHECK: %[[KINDPTR:.*]] = getelementptr {{.*}} %[[A]], i32 0, i32 0 // CHECK: %[[KIND:.*]] = load i8, i8* %[[KINDPTR]], align 4 // CHECK: %[[NOT_0:.*]] = icmp ne i8 %[[KIND]], 0 // CHECK: br i1 %[[NOT_0]], label %[[CONT1:.*]], label %[[HANDLE0:.*]], !prof -// CHECK: [[HANDLE0]] +// CHECK: [[HANDLE0]]: // CHECK: %[[DATA0:.*]] = ptrtoint i8* %[[DATA]] to i64, // CHECK: %[[ADDR0:.*]] = ptrtoint i8* %[[ADDR]] to i64, // CHECK: call void @__ubsan_handle_cfi_check_fail(i64 %[[DATA0]], i64 %[[ADDR0]]) // CHECK: br label %[[CONT1]] -// CHECK: [[CONT1]] +// CHECK: [[CONT1]]: // CHECK: %[[NOT_1:.*]] = icmp ne i8 %[[KIND]], 1 // CHECK: br i1 %[[NOT_1]], label %[[CONT2:.*]], label %[[HANDLE1:.*]], !nosanitize -// CHECK: [[HANDLE1]] +// CHECK: [[HANDLE1]]: // CHECK-NEXT: call void @llvm.trap() // CHECK-NEXT: unreachable -// CHECK: [[CONT2]] +// CHECK: [[CONT2]]: // CHECK: %[[NOT_2:.*]] = icmp ne i8 %[[KIND]], 2 // CHECK: br i1 %[[NOT_2]], label %[[CONT3:.*]], label %[[HANDLE2:.*]], !prof -// CHECK: [[HANDLE2]] +// CHECK: [[HANDLE2]]: // CHECK: %[[DATA2:.*]] = ptrtoint i8* %[[DATA]] to i64, // CHECK: %[[ADDR2:.*]] = ptrtoint i8* %[[ADDR]] to i64, // CHECK: call void @__ubsan_handle_cfi_check_fail_abort(i64 %[[DATA2]], i64 %[[ADDR2]]) // CHECK: unreachable -// CHECK: [[CONT3]] +// CHECK: [[CONT3]]: // CHECK: %[[NOT_3:.*]] = icmp ne i8 %[[KIND]], 3 // CHECK: br i1 %[[NOT_3]], label %[[CONT4:.*]], label %[[HANDLE3:.*]], !prof -// CHECK: [[HANDLE3]] +// CHECK: [[HANDLE3]]: // CHECK: %[[DATA3:.*]] = ptrtoint i8* %[[DATA]] to i64, // CHECK: %[[ADDR3:.*]] = ptrtoint i8* %[[ADDR]] to i64, // CHECK: call void @__ubsan_handle_cfi_check_fail(i64 %[[DATA3]], i64 %[[ADDR3]]) // CHECK: br label %[[CONT4]] -// CHECK: [[CONT4]] +// CHECK: [[CONT4]]: // CHECK: %[[NOT_4:.*]] = icmp ne i8 %[[KIND]], 4 // CHECK: br i1 %[[NOT_4]], label %[[CONT5:.*]], label %[[HANDLE4:.*]], !nosanitize -// CHECK: [[HANDLE4]] +// CHECK: [[HANDLE4]]: // CHECK-NEXT: call void @llvm.trap() // CHECK-NEXT: unreachable -// CHECK: [[CONT5]] +// CHECK: [[CONT5]]: // CHECK: ret void ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16738: Fix invalid casts in .
eugenis added a comment. In http://reviews.llvm.org/D16738#340175, @EricWF wrote: > > This also could be fixed in a different way by replacing C-style > > > casts with reinterpret_cast<>, which, from my reading of the > > > standard, is allowed in this context. > > > I agree that using `void*` to represent raw memory is the better approach > than `reinterpret_cast<>()`. > However I'm concerned that changing the signature (and mangling) of `virtual > void __clone(...)` could cause ABI problems. > I *think* this should be "safe" because the VTable's mangled name doesn't > change. but if I'm wrong we must use `reinterpret_cast<>` for calls to > `__clone(...)`. > > The parts of the patch that don't affect `__clone(...)` LGTM. You can commit > them separably if you want. > > > That would not help with CFI > > > though, which still flags such casts as invalid (yes, it is stricter that > > the standard). > > > I'm sure there are alternative ways to make CFI shut up. Perhaps we could do > the `Buffer* -> Base*` conversion inside a blacklisted function (akin to > std::launder)? > It would also be nice to have "`__attribute__((__no_sanitize__("cfi")))`. We do have this attribute. Repository: rL LLVM http://reviews.llvm.org/D16738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis created this revision. eugenis added reviewers: pcc, kcc. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. Avoid crashing when printing diagnostics for vtable-related CFI errors. In diagnostic mode, the frontend does an additional check of the vtable pointer against the set of all known vtable addresses and lets the runtime handler know if it is safe to inspect the vtable. Repository: rL LLVM http://reviews.llvm.org/D16823 Files: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp test/CodeGen/cfi-check-fail.c test/CodeGenCXX/cfi-cast.cpp test/CodeGenCXX/cfi-vcall.cpp Index: test/CodeGenCXX/cfi-vcall.cpp === --- test/CodeGenCXX/cfi-vcall.cpp +++ test/CodeGenCXX/cfi-vcall.cpp @@ -55,7 +55,7 @@ // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}cfi-vcall.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } -// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } +// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+23]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } // ITANIUM: define void @_Z2afP1A // MS: define void @"\01?af@@YAXPEAUA@@@Z" @@ -68,10 +68,12 @@ // CHECK: [[TRAPBB]] // NDIAG-NEXT: call void @llvm.trap() // NDIAG-NEXT: unreachable + // DIAG-NEXT: [[VTVALID0:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT]], metadata !"all-vtables") // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint i8* [[VT]] to i64 - // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-NEXT: [[VTVALID:%[^ ]*]] = zext i1 [[VTVALID0]] to i64 + // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-ABORT-NEXT: unreachable - // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-RECOVER-NEXT: br label %[[CONTBB]] // CHECK: [[CONTBB]] @@ -157,32 +159,45 @@ } -// Check for the expected number of elements (9 or 15 respectively). -// MS: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){8}]]} -// ITANIUM: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){14}]]} +// Check for the expected number of elements (15 or 23 respectively). +// MS: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){15}]]} +// ITANIUM: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){23}]]} // ITANIUM-DAG: !{!"_ZTS1A", [3 x i8*]* @_ZTV1A, i64 16} +// ITANIUM-DAG: !{!"all-vtables", [3 x i8*]* @_ZTV1A, i64 16} // ITANIUM-DAG: !{!"_ZTS1A", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} +// ITANIUM-DAG: !{!"all-vtables", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64} +// ITANIUM-DAG: !{!"all-vtables", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64} // ITANIUM-DAG: !{!"_ZTS1C", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} +// ITANIUM-DAG: !{!"all-vtables", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} // ITANIUM-DAG: !{!"_ZTS1C", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 88} +// ITANIUM-DAG: !{!"all-vtables", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 88} // ITANIUM-DAG: !{![[DTYPE]], [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [7 x i8*]* @_ZTV1B, i64 32} +// ITANIUM-DAG: !{!"all-vtables", [7 x i8*]* @_ZTV1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [7 x i8*]* @_ZTV1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [5 x i8*]* @_ZTV1C, i64 32} // ITANIUM-DAG: !{!"_ZTS1C", [5 x i8*]* @_ZTV1C, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [3 x i8*]* @_ZTVZ3foovE2FA, i64 16} // ITANIUM-DAG: !{!{{[0-9]+}}, [3 x i8*]* @_ZTVZ3foovE2FA, i64 16} // MS-DAG: !{!"?AUA@@", [2 x i8*]* @[[VTA]], i64 8} +// MS-DAG: !{!"all-vtables", [2 x i8*]* @[[VTA]], i64 8} // MS-DAG: !{!"?AUB@@", [3 x i8*]* @[[VTB]], i64 8} +// MS-DAG: !{!"all-vtables", [3 x i8*]* @[[VTB]], i64 8} // MS-DAG: !{!"?AUA@@", [2 x i8*]* @[[VTAinB]], i64 8} +// MS-DAG: !{!"all-vtables", [2 x i8*]*
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis added inline comments. Comment at: lib/CodeGen/CGExpr.cpp:2494 @@ +2493,3 @@ + llvm::Value *ValidVtable = nullptr; + if (CheckAndAppendValidVtable) { +llvm::Value *AllVtables = llvm::MetadataAsValue::get( samsonov wrote: > This is really ugly. Why are you not passing it down in DynamicArgs? Is it > performance penalty you don't want to pay if the check will not succeed? How > large will it be? Yes, I want this code to be on the failing side of the check. This would cost about the same as the check itself, so I suspect it could double the overhead. Repository: rL LLVM http://reviews.llvm.org/D16823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis added inline comments. Comment at: lib/CodeGen/CGExpr.cpp:2494 @@ +2493,3 @@ + llvm::Value *ValidVtable = nullptr; + if (CheckAndAppendValidVtable) { +llvm::Value *AllVtables = llvm::MetadataAsValue::get( pcc wrote: > eugenis wrote: > > samsonov wrote: > > > This is really ugly. Why are you not passing it down in DynamicArgs? Is > > > it performance penalty you don't want to pay if the check will not > > > succeed? How large will it be? > > Yes, I want this code to be on the failing side of the check. > > This would cost about the same as the check itself, so I suspect it could > > double the overhead. > > > I would just emit the call unconditionally. We don't care too much about the > performance in non-trapping mode, and if it becomes a problem in practice we > can see if we can have the optimizer move the call into the conditional block > (which I suspect it already knows how to do). I care about performance in non-trapping mode. Doing this change would not make the code any less ugly. For example, EmitCheck may not use the argument if the check has -fsanitize-trap behaviour, in which case we get an unused llvm.bitset.test call that affects some of the clang tests. Repository: rL LLVM http://reviews.llvm.org/D16823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis updated this revision to Diff 46718. eugenis added a comment. Moved bitset.text call outside. LLVM is smart enough to sink it along the cold branch, so performance should not suffer. Repository: rL LLVM http://reviews.llvm.org/D16823 Files: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenModule.cpp test/CodeGen/cfi-check-fail.c test/CodeGenCXX/cfi-cast.cpp test/CodeGenCXX/cfi-vcall.cpp Index: test/CodeGenCXX/cfi-vcall.cpp === --- test/CodeGenCXX/cfi-vcall.cpp +++ test/CodeGenCXX/cfi-vcall.cpp @@ -55,23 +55,25 @@ // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}cfi-vcall.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } -// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } +// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+23]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } // ITANIUM: define void @_Z2afP1A // MS: define void @"\01?af@@YAXPEAUA@@@Z" void af(A *a) { // ITANIUM: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT:%[^ ]*]], metadata !"_ZTS1A") // MS: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT:%[^ ]*]], metadata !"?AUA@@") + // DIAG-NEXT: [[VTVALID0:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT]], metadata !"all-vtables") // CHECK-NEXT: br i1 [[P]], label %[[CONTBB:[^ ,]*]], label %[[TRAPBB:[^ ,]*]] // CHECK-NEXT: {{^$}} // CHECK: [[TRAPBB]] // NDIAG-NEXT: call void @llvm.trap() // NDIAG-NEXT: unreachable // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint i8* [[VT]] to i64 - // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-NEXT: [[VTVALID:%[^ ]*]] = zext i1 [[VTVALID0]] to i64 + // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-ABORT-NEXT: unreachable - // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-RECOVER-NEXT: br label %[[CONTBB]] // CHECK: [[CONTBB]] @@ -157,32 +159,45 @@ } -// Check for the expected number of elements (9 or 15 respectively). -// MS: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){8}]]} -// ITANIUM: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){14}]]} +// Check for the expected number of elements (15 or 23 respectively). +// MS: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){15}]]} +// ITANIUM: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){23}]]} // ITANIUM-DAG: !{!"_ZTS1A", [3 x i8*]* @_ZTV1A, i64 16} +// ITANIUM-DAG: !{!"all-vtables", [3 x i8*]* @_ZTV1A, i64 16} // ITANIUM-DAG: !{!"_ZTS1A", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} +// ITANIUM-DAG: !{!"all-vtables", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64} +// ITANIUM-DAG: !{!"all-vtables", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64} // ITANIUM-DAG: !{!"_ZTS1C", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} +// ITANIUM-DAG: !{!"all-vtables", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} // ITANIUM-DAG: !{!"_ZTS1C", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 88} +// ITANIUM-DAG: !{!"all-vtables", [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 88} // ITANIUM-DAG: !{![[DTYPE]], [12 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [7 x i8*]* @_ZTV1B, i64 32} +// ITANIUM-DAG: !{!"all-vtables", [7 x i8*]* @_ZTV1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [7 x i8*]* @_ZTV1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [5 x i8*]* @_ZTV1C, i64 32} // ITANIUM-DAG: !{!"_ZTS1C", [5 x i8*]* @_ZTV1C, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [3 x i8*]* @_ZTVZ3foovE2FA, i64 16} // ITANIUM-DAG: !{!{{[0-9]+}}, [3 x i8*]* @_ZTVZ3foovE2FA, i64 16} // MS-DAG: !{!"?AUA@@", [2 x i8*]* @[[VTA]], i64 8} +// MS-DAG: !{!"all-vtables", [2 x i8*]* @[[VTA]], i64 8} // MS-DAG: !{!"?AUB@@", [3 x i8*]* @[[VTB]], i64 8} +// MS-DAG: !{!"all-vtables", [3 x i8*]* @[[VTB]], i64 8} // MS-DAG: !{!"?AUA@@", [2 x i8*]* @[[VTAinB]], i64 8} +// MS-DAG:
[PATCH] D16738: Fix invalid casts in .
eugenis created this revision. eugenis added reviewers: EricWF, mclow.lists. eugenis added subscribers: cfe-commits, pcc. eugenis set the repository for this revision to rL LLVM. static_cast of a pointer to object before the start of the object's lifetime has undefined behavior (c++14 p3.8) This code triggers CFI warnings. This also could be fixed in a different way by replacing C-style casts with reinterpret_cast<>, which, from my reading of the standard, is allowed in this context. That would not help with CFI though, which still flags such casts as invalid (yes, it is stricter that the standard). Repository: rL LLVM http://reviews.llvm.org/D16738 Files: include/functional Index: include/functional === --- include/functional +++ include/functional @@ -1440,7 +1440,7 @@ _LIBCPP_INLINE_VISIBILITY __base() {} _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} virtual __base* __clone() const = 0; -virtual void __clone(__base*) const = 0; +virtual void __clone(void*) const = 0; virtual void destroy() _NOEXCEPT = 0; virtual void destroy_deallocate() _NOEXCEPT = 0; virtual _Rp operator()(_ArgTypes&& ...) = 0; @@ -1477,7 +1477,7 @@ : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), _VSTD::forward_as_tuple(_VSTD::move(__a))) {} virtual __base<_Rp(_ArgTypes...)>* __clone() const; -virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; +virtual void __clone(void*) const; virtual void destroy() _NOEXCEPT; virtual void destroy_deallocate() _NOEXCEPT; virtual _Rp operator()(_ArgTypes&& ... __arg); @@ -1502,7 +1502,7 @@ template void -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(void* __p) const { ::new (__p) __func(__f_.first(), __f_.second()); } @@ -1660,10 +1660,10 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (const __base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { +__f.__f_->__clone(&__buf_); __f_ = (__base*)&__buf_; -__f.__f_->__clone(__f_); } else __f_ = __f.__f_->__clone(); @@ -1676,10 +1676,10 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (const __base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { +__f.__f_->__clone(&__buf_); __f_ = (__base*)&__buf_; -__f.__f_->__clone(__f_); } else __f_ = __f.__f_->__clone(); @@ -1690,10 +1690,10 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { +__f.__f_->__clone(&__buf_); __f_ = (__base*)&__buf_; -__f.__f_->__clone(__f_); } else { @@ -1709,10 +1709,10 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { +__f.__f_->__clone(&__buf_); __f_ = (__base*)&__buf_; -__f.__f_->__clone(__f_); } else { @@ -1736,8 +1736,8 @@ typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) { +::new (&__buf_) _FF(_VSTD::move(__f)); __f_ = (__base*)&__buf_; -::new (__f_) _FF(_VSTD::move(__f)); } else { @@ -1791,17 +1791,17 @@ function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); __f_ = 0; if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if ((void *)__f.__f_ == &__f.__buf_) { +__f.__f_->__clone(&__buf_); __f_ = (__base*)&__buf_; -__f.__f_->__clone(__f_); } else { @@ -1815,7 +1815,7 @@ function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1840,7 +1840,7 @@ template function<_Rp(_ArgTypes...)>::~function() { -if (__f_ == (__base*)&__buf_) +if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1850,31 +1850,31 @@ void function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT { -if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) +if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) { typename aligned_storage::type __tempbuf; +
Re: [PATCH] D16738: Fix invalid casts in .
eugenis added a comment. http://clang.llvm.org/docs/ControlFlowIntegrity.html Basically it says that the cast to __base is done on a memory that does not contain an object of type __base (based on the vptr value). Repository: rL LLVM http://reviews.llvm.org/D16738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis closed this revision. eugenis added a comment. http://llvm.org/viewvc/llvm-project?rev=259716=rev Repository: rL LLVM http://reviews.llvm.org/D16823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r259716 - [cfi] Safe handling of unaddressable vtable pointers (clang).
Author: eugenis Date: Wed Feb 3 16:18:55 2016 New Revision: 259716 URL: http://llvm.org/viewvc/llvm-project?rev=259716=rev Log: [cfi] Safe handling of unaddressable vtable pointers (clang). Avoid crashing when printing diagnostics for vtable-related CFI errors. In diagnostic mode, the frontend does an additional check of the vtable pointer against the set of all known vtable addresses and lets the runtime handler know if it is safe to inspect the vtable. http://reviews.llvm.org/D16823 Modified: cfe/trunk/lib/CodeGen/CGClass.cpp cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/CodeGen/CodeGenModule.h cfe/trunk/test/CodeGen/cfi-check-fail.c cfe/trunk/test/CodeGenCXX/cfi-cast.cpp cfe/trunk/test/CodeGenCXX/cfi-vcall.cpp Modified: cfe/trunk/lib/CodeGen/CGClass.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=259716=259715=259716=diff == --- cfe/trunk/lib/CodeGen/CGClass.cpp (original) +++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Feb 3 16:18:55 2016 @@ -2607,10 +2607,22 @@ void CodeGenFunction::EmitVTablePtrCheck auto TypeId = CGM.CreateCfiIdForTypeMetadata(MD); if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && TypeId) { EmitCfiSlowPathCheck(M, BitSetTest, TypeId, CastedVTable, StaticData); - } else { -EmitCheck(std::make_pair(BitSetTest, M), "cfi_check_fail", StaticData, - CastedVTable); +return; } + + if (CGM.getCodeGenOpts().SanitizeTrap.has(M)) { +EmitTrapCheck(BitSetTest); +return; + } + + llvm::Value *AllVtables = llvm::MetadataAsValue::get( + CGM.getLLVMContext(), + llvm::MDString::get(CGM.getLLVMContext(), "all-vtables")); + llvm::Value *ValidVtable = + Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::bitset_test), + {CastedVTable, AllVtables}); + EmitCheck(std::make_pair(BitSetTest, M), "cfi_check_fail", StaticData, +{CastedVTable, ValidVtable}); } // FIXME: Ideally Expr::IgnoreParenNoopCasts should do this, but it doesn't do Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=259716=259715=259716=diff == --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Feb 3 16:18:55 2016 @@ -2636,6 +2636,14 @@ void CodeGenFunction::EmitCfiCheckFail() Address CheckKindAddr(V, getIntAlign()); llvm::Value *CheckKind = Builder.CreateLoad(CheckKindAddr); + llvm::Value *AllVtables = llvm::MetadataAsValue::get( + CGM.getLLVMContext(), + llvm::MDString::get(CGM.getLLVMContext(), "all-vtables")); + llvm::Value *ValidVtable = Builder.CreateZExt( + Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::bitset_test), + {Addr, AllVtables}), + IntPtrTy); + const std::pairCheckKinds[] = { {CFITCK_VCall, SanitizerKind::CFIVCall}, {CFITCK_NVCall, SanitizerKind::CFINVCall}, @@ -2649,7 +2657,8 @@ void CodeGenFunction::EmitCfiCheckFail() SanitizerMask Mask = CheckKindMaskPair.second; llvm::Value *Cond = Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(Int8Ty, Kind)); -EmitCheck(std::make_pair(Cond, Mask), "cfi_check_fail", {}, {Data, Addr}); +EmitCheck(std::make_pair(Cond, Mask), "cfi_check_fail", {}, + {Data, Addr, ValidVtable}); } FinishFunction(); @@ -3970,7 +3979,8 @@ RValue CodeGenFunction::EmitCall(QualTyp CastedCallee, StaticData); } else { EmitCheck(std::make_pair(BitSetTest, SanitizerKind::CFIICall), -"cfi_check_fail", StaticData, CastedCallee); +"cfi_check_fail", StaticData, +{CastedCallee, llvm::UndefValue::get(IntPtrTy)}); } } Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=259716=259715=259716=diff == --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Feb 3 16:18:55 2016 @@ -4021,6 +4021,20 @@ llvm::Metadata *CodeGenModule::CreateMet return InternalId; } +/// Returns whether this module needs the "all-vtables" bitset. +bool CodeGenModule::NeedAllVtablesBitSet() const { + // Returns true if at least one of vtable-based CFI checkers is enabled and + // is not in the trapping mode. + return ((LangOpts.Sanitize.has(SanitizerKind::CFIVCall) && + !CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFIVCall)) || + (LangOpts.Sanitize.has(SanitizerKind::CFINVCall) && + !CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFINVCall)) || +
Re: [PATCH] D16738: Fix invalid casts in .
eugenis updated this revision to Diff 46857. eugenis added a comment. How about this? Repository: rL LLVM http://reviews.llvm.org/D16738 Files: include/__config include/functional Index: include/functional === --- include/functional +++ include/functional @@ -1564,6 +1564,10 @@ typename aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; +_LIBCPP_NO_CFI static __base *__as_base(void *p) { + return reinterpret_cast<__base*>(p); +} + template ::value && __invokable<_Fp&, _ArgTypes...>::value> struct __callable; @@ -1662,7 +1666,7 @@ __f_ = 0; else if (__f.__f_ == (const __base*)&__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1678,7 +1682,7 @@ __f_ = 0; else if (__f.__f_ == (const __base*)&__f.__buf_) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1690,9 +1694,9 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if (__f.__f_ == __as_base(&__f.__buf_)) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1709,9 +1713,9 @@ { if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if (__f.__f_ == __as_base(&__f.__buf_)) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1736,8 +1740,7 @@ typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) { -__f_ = (__base*)&__buf_; -::new (__f_) _FF(_VSTD::move(__f)); +__f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); } else { @@ -1766,8 +1769,7 @@ if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) { -__f_ = (__base*)&__buf_; -::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a)); +__f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); } else { @@ -1791,16 +1793,16 @@ function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if (__f_ == __as_base(&__buf_)) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); __f_ = 0; if (__f.__f_ == 0) __f_ = 0; -else if (__f.__f_ == (__base*)&__f.__buf_) +else if (__f.__f_ == __as_base(&__f.__buf_)) { -__f_ = (__base*)&__buf_; +__f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1815,7 +1817,7 @@ function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT { -if (__f_ == (__base*)&__buf_) +if (__f_ == __as_base(&__buf_)) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1840,7 +1842,7 @@ template function<_Rp(_ArgTypes...)>::~function() { -if (__f_ == (__base*)&__buf_) +if (__f_ == __as_base(&__buf_)) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1850,34 +1852,34 @@ void function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT { -if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) +if (__f_ == __as_base(&__buf_) && __f.__f_ == __as_base(&__f.__buf_)) { typename aligned_storage::type __tempbuf; -__base* __t = (__base*)&__tempbuf; +__base* __t = __as_base(&__tempbuf); __f_->__clone(__t); __f_->destroy(); __f_ = 0; -__f.__f_->__clone((__base*)&__buf_); +__f.__f_->__clone(__as_base(&__buf_)); __f.__f_->destroy(); __f.__f_ = 0; -__f_ = (__base*)&__buf_; -__t->__clone((__base*)&__f.__buf_); +__f_ = __as_base(&__buf_); +__t->__clone(__as_base(&__f.__buf_)); __t->destroy(); -__f.__f_ = (__base*)&__f.__buf_; +__f.__f_ = __as_base(&__f.__buf_); } -else if (__f_ == (__base*)&__buf_) +else if (__f_ == __as_base(&__buf_)) { -__f_->__clone((__base*)&__f.__buf_); +__f_->__clone(__as_base(&__f.__buf_)); __f_->destroy(); __f_ = __f.__f_; -__f.__f_ = (__base*)&__f.__buf_; +__f.__f_ = __as_base(&__f.__buf_); } -else if (__f.__f_ == (__base*)&__f.__buf_) +else if (__f.__f_ == __as_base(&__f.__buf_)) { -__f.__f_->__clone((__base*)&__buf_); +__f.__f_->__clone(__as_base(&__buf_));
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis added inline comments. Comment at: lib/CodeGen/CGClass.cpp:2608 @@ -2607,3 +2607,3 @@ auto TypeId = CGM.CreateCfiIdForTypeMetadata(MD); if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && TypeId) { EmitCfiSlowPathCheck(M, BitSetTest, TypeId, CastedVTable, StaticData); samsonov wrote: > Can we rewrite this as if-elseif-else block now? even better, with 2 early returns. Repository: rL LLVM http://reviews.llvm.org/D16823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis updated this revision to Diff 46807. Repository: rL LLVM http://reviews.llvm.org/D16823 Files: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/cfi-check-fail.c test/CodeGenCXX/cfi-cast.cpp test/CodeGenCXX/cfi-vcall.cpp Index: test/CodeGenCXX/cfi-vcall.cpp === --- test/CodeGenCXX/cfi-vcall.cpp +++ test/CodeGenCXX/cfi-vcall.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=NDIAG %s -// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=DIAG --check-prefix=DIAG-ABORT %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=ITANIUM-NDIAG --check-prefix=NDIAG %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s // RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS --check-prefix=NDIAG %s @@ -55,23 +55,25 @@ // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}cfi-vcall.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } -// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } +// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+23]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } // ITANIUM: define void @_Z2afP1A // MS: define void @"\01?af@@YAXPEAUA@@@Z" void af(A *a) { // ITANIUM: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT:%[^ ]*]], metadata !"_ZTS1A") // MS: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT:%[^ ]*]], metadata !"?AUA@@") + // DIAG-NEXT: [[VTVALID0:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT]], metadata !"all-vtables") // CHECK-NEXT: br i1 [[P]], label %[[CONTBB:[^ ,]*]], label %[[TRAPBB:[^ ,]*]] // CHECK-NEXT: {{^$}} // CHECK: [[TRAPBB]] // NDIAG-NEXT: call void @llvm.trap() // NDIAG-NEXT: unreachable // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint i8* [[VT]] to i64 - // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-NEXT: [[VTVALID:%[^ ]*]] = zext i1 [[VTVALID0]] to i64 + // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-ABORT-NEXT: unreachable - // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-RECOVER-NEXT: br label %[[CONTBB]] // CHECK: [[CONTBB]] @@ -157,32 +159,47 @@ } -// Check for the expected number of elements (9 or 15 respectively). -// MS: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){8}]]} -// ITANIUM: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){14}]]} +// Check for the expected number of elements (15 or 23 respectively). +// MS-NDIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){9}]]} +// MS-DIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){15}]]} +// ITANIUM-NDIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){14}]]} +// ITANIUM-DIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){23}]]} // ITANIUM-DAG: !{!"_ZTS1A", [3 x i8*]* @_ZTV1A, i64 16} +// ITANIUM-DIAG-DAG: !{!"all-vtables", [3 x i8*]* @_ZTV1A, i64 16} // ITANIUM-DAG: !{!"_ZTS1A", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} +// ITANIUM-DIAG-DAG: !{!"all-vtables", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64} +// ITANIUM-DIAG-DAG: !{!"all-vtables", [9 x i8*]*
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis updated this revision to Diff 46723. eugenis marked an inline comment as done. Repository: rL LLVM http://reviews.llvm.org/D16823 Files: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/cfi-check-fail.c test/CodeGenCXX/cfi-cast.cpp test/CodeGenCXX/cfi-vcall.cpp Index: test/CodeGenCXX/cfi-vcall.cpp === --- test/CodeGenCXX/cfi-vcall.cpp +++ test/CodeGenCXX/cfi-vcall.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=NDIAG %s -// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=DIAG --check-prefix=DIAG-ABORT %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=ITANIUM-NDIAG --check-prefix=NDIAG %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s // RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS --check-prefix=NDIAG %s @@ -55,23 +55,25 @@ // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}cfi-vcall.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } -// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } +// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+23]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } // ITANIUM: define void @_Z2afP1A // MS: define void @"\01?af@@YAXPEAUA@@@Z" void af(A *a) { // ITANIUM: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT:%[^ ]*]], metadata !"_ZTS1A") // MS: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT:%[^ ]*]], metadata !"?AUA@@") + // DIAG-NEXT: [[VTVALID0:%[^ ]*]] = call i1 @llvm.bitset.test(i8* [[VT]], metadata !"all-vtables") // CHECK-NEXT: br i1 [[P]], label %[[CONTBB:[^ ,]*]], label %[[TRAPBB:[^ ,]*]] // CHECK-NEXT: {{^$}} // CHECK: [[TRAPBB]] // NDIAG-NEXT: call void @llvm.trap() // NDIAG-NEXT: unreachable // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint i8* [[VT]] to i64 - // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-NEXT: [[VTVALID:%[^ ]*]] = zext i1 [[VTVALID0]] to i64 + // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-ABORT-NEXT: unreachable - // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) + // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]], i64 [[VTVALID]]) // DIAG-RECOVER-NEXT: br label %[[CONTBB]] // CHECK: [[CONTBB]] @@ -157,32 +159,47 @@ } -// Check for the expected number of elements (9 or 15 respectively). -// MS: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){8}]]} -// ITANIUM: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){14}]]} +// Check for the expected number of elements (15 or 23 respectively). +// MS-NDIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){9}]]} +// MS-DIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){15}]]} +// ITANIUM-NDIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){14}]]} +// ITANIUM-DIAG: !llvm.bitsets = !{[[X:[^,]*(,[^,]*){23}]]} // ITANIUM-DAG: !{!"_ZTS1A", [3 x i8*]* @_ZTV1A, i64 16} +// ITANIUM-DIAG-DAG: !{!"all-vtables", [3 x i8*]* @_ZTV1A, i64 16} // ITANIUM-DAG: !{!"_ZTS1A", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} +// ITANIUM-DIAG-DAG: !{!"all-vtables", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1B", [7 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} // ITANIUM-DAG: !{!"_ZTS1A", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64} +// ITANIUM-DIAG-DAG:
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis added inline comments. Comment at: lib/CodeGen/CodeGenModule.cpp:4053 @@ +4052,3 @@ + + if (!CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFIVCall) || + !CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFINVCall) || I don't like emitting all these bitset entries if they are not needed. Fixed. Repository: rL LLVM http://reviews.llvm.org/D16823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16823: [cfi] Safe handling of unaddressable vtable pointers (clang).
eugenis added inline comments. Comment at: lib/CodeGen/CGExpr.cpp:2642 @@ +2641,3 @@ + llvm::MDString::get(CGM.getLLVMContext(), "all-vtables")); + llvm::Value *ValidVtable = Builder.CreateZExt( + Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::bitset_test), samsonov wrote: > This is almost the same as EmitVTablePtrCheck, but with ZExt? Is the > difference intentional/important? Is it possible to extract this logic > (getting "all-vtables" metadata and running bitset test) to a function? Not important. Zext makes the test a bit simpler. Extracting these two lines to a function is surely possible, but is it worth it? Repository: rL LLVM http://reviews.llvm.org/D16823 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D17360: [cfi] Fix handling of sanitize trap/recover flags in the cross-DSO CFI mode.
eugenis updated the summary for this revision. eugenis updated this revision to Diff 49115. eugenis added a comment. OK, done. Please take another look. This is inferior to the original patch in terms of functionality, but the implementation is a lot simpler. Repository: rL LLVM http://reviews.llvm.org/D17360 Files: lib/CodeGen/CGExpr.cpp test/CodeGen/cfi-check-fail.c test/CodeGen/cfi-check-fail2.c Index: test/CodeGen/cfi-check-fail2.c === --- /dev/null +++ test/CodeGen/cfi-check-fail2.c @@ -0,0 +1,70 @@ +// __cfi_check_fail codegen when not all CFI checkers are enabled. +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \ +// RUN: -fsanitize=cfi-vcall \ +// RUN: -emit-llvm -o - %s | FileCheck %s + +void caller(void (*f)()) { + f(); +} + +// CHECK: define weak_odr hidden void @__cfi_check_fail(i8*, i8*) { +// CHECK: store i8* %0, i8** %[[ALLOCA0:.*]], align 8 +// CHECK: store i8* %1, i8** %[[ALLOCA1:.*]], align 8 +// CHECK: %[[DATA:.*]] = load i8*, i8** %[[ALLOCA0]], align 8 +// CHECK: %[[ADDR:.*]] = load i8*, i8** %[[ALLOCA1]], align 8 +// CHECK: %[[ICMP_NOT_NULL:.*]] = icmp ne i8* %[[DATA]], null +// CHECK: br i1 %[[ICMP_NOT_NULL]], label %[[CONT0:.*]], label %[[TRAP:.*]], + +// CHECK: [[TRAP]]: +// CHECK-NEXT: call void @llvm.trap() +// CHECK-NEXT: unreachable + +// CHECK: [[CONT0]]: +// CHECK: %[[A:.*]] = bitcast i8* %[[DATA]] to { i8, { i8*, i32, i32 }, i8* }* +// CHECK: %[[KINDPTR:.*]] = getelementptr {{.*}} %[[A]], i32 0, i32 0 +// CHECK: %[[KIND:.*]] = load i8, i8* %[[KINDPTR]], align 4 +// CHECK: %[[VTVALID0:.*]] = call i1 @llvm.bitset.test(i8* %[[ADDR]], metadata !"all-vtables") +// CHECK: %[[VTVALID:.*]] = zext i1 %[[VTVALID0]] to i64 +// CHECK: %[[NOT_0:.*]] = icmp ne i8 %[[KIND]], 0 +// CHECK: br i1 %[[NOT_0]], label %[[CONT1:.*]], label %[[HANDLE0:.*]], !prof + +// CHECK: [[HANDLE0]]: +// CHECK: %[[DATA0:.*]] = ptrtoint i8* %[[DATA]] to i64, +// CHECK: %[[ADDR0:.*]] = ptrtoint i8* %[[ADDR]] to i64, +// CHECK: call void @__ubsan_handle_cfi_check_fail_abort(i64 %[[DATA0]], i64 %[[ADDR0]], i64 %[[VTVALID]]) +// CHECK: unreachable + +// CHECK: [[CONT1]]: +// CHECK: %[[NOT_1:.*]] = icmp ne i8 %[[KIND]], 1 +// CHECK: br i1 %[[NOT_1]], label %[[CONT2:.*]], label %[[HANDLE1:.*]], !nosanitize + +// CHECK: [[HANDLE1]]: +// CHECK-NEXT: call void @llvm.trap() +// CHECK-NEXT: unreachable + +// CHECK: [[CONT2]]: +// CHECK: %[[NOT_2:.*]] = icmp ne i8 %[[KIND]], 2 +// CHECK: br i1 %[[NOT_2]], label %[[CONT3:.*]], label %[[HANDLE2:.*]], !nosanitize + +// CHECK: [[HANDLE2]]: +// CHECK-NEXT: call void @llvm.trap() +// CHECK-NEXT: unreachable + +// CHECK: [[CONT3]]: +// CHECK: %[[NOT_3:.*]] = icmp ne i8 %[[KIND]], 3 +// CHECK: br i1 %[[NOT_3]], label %[[CONT4:.*]], label %[[HANDLE3:.*]], !nosanitize + +// CHECK: [[HANDLE3]]: +// CHECK-NEXT: call void @llvm.trap() +// CHECK-NEXT: unreachable + +// CHECK: [[CONT4]]: +// CHECK: %[[NOT_4:.*]] = icmp ne i8 %[[KIND]], 4 +// CHECK: br i1 %[[NOT_4]], label %[[CONT5:.*]], label %[[HANDLE4:.*]], !nosanitize + +// CHECK: [[HANDLE4]]: +// CHECK-NEXT: call void @llvm.trap() +// CHECK-NEXT: unreachable + +// CHECK: [[CONT5]]: +// CHECK: ret void Index: test/CodeGen/cfi-check-fail.c === --- test/CodeGen/cfi-check-fail.c +++ test/CodeGen/cfi-check-fail.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \ +// RUN: -fsanitize=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \ // RUN: -fsanitize-trap=cfi-icall,cfi-nvcall -fsanitize-recover=cfi-vcall,cfi-unrelated-cast \ // RUN: -emit-llvm -o - %s | FileCheck %s Index: lib/CodeGen/CGExpr.cpp === --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2483,14 +2483,12 @@ CheckRecoverableKind RecoverKind = getRecoverableKind(Checked[0].second); // In cross-DSO CFI mode this code is used to generate __cfi_check_fail, which // includes all checks, even those that are not in SanOpts. - assert(CGM.getCodeGenOpts().SanitizeCfiCrossDso || - SanOpts.has(Checked[0].second)); + assert(SanOpts.has(Checked[0].second)); #ifndef NDEBUG for (int i = 1, n = Checked.size(); i < n; ++i) { assert(RecoverKind == getRecoverableKind(Checked[i].second) && "All recoverable kinds in a single check must be same!"); -assert(CGM.getCodeGenOpts().SanitizeCfiCrossDso || - SanOpts.has(Checked[i].second)); +assert(SanOpts.has(Checked[i].second)); } #endif @@ -2672,8 +2670,11 @@ SanitizerMask Mask = CheckKindMaskPair.second; llvm::Value *Cond = Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(Int8Ty,
Re: [PATCH] D15699: [cfi] Cross-DSO CFI diagnostic mode (clang part)
eugenis updated this revision to Diff 45292. Repository: rL LLVM http://reviews.llvm.org/D15699 Files: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/Driver/Tools.cpp test/CodeGen/cfi-check-fail.c test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/CodeGenCXX/cfi-vcall.cpp Index: test/CodeGenCXX/cfi-vcall.cpp === --- test/CodeGenCXX/cfi-vcall.cpp +++ test/CodeGenCXX/cfi-vcall.cpp @@ -55,7 +55,7 @@ // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}cfi-vcall.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } -// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8 } { { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]], i8 0 } +// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } // ITANIUM: define void @_Z2afP1A // MS: define void @"\01?af@@YAXPEAUA@@@Z" @@ -69,9 +69,9 @@ // NDIAG-NEXT: call void @llvm.trap() // NDIAG-NEXT: unreachable // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint i8* [[VT]] to i64 - // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_bad_type_abort(i8* bitcast ({{.*}} @[[BADTYPESTATIC]] to i8*), i64 [[VTINT]]) + // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) // DIAG-ABORT-NEXT: unreachable - // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_bad_type(i8* bitcast ({{.*}} @[[BADTYPESTATIC]] to i8*), i64 [[VTINT]]) + // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) // DIAG-RECOVER-NEXT: br label %[[CONTBB]] // CHECK: [[CONTBB]] Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- test/CodeGenCXX/cfi-cross-dso.cpp +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -34,8 +34,8 @@ // MS: %[[TEST:.*]] = call i1 @llvm.bitset.test(i8* %[[VT2]], metadata !"?AUA@@"), !nosanitize // CHECK: br i1 %[[TEST]], label %[[CONT:.*]], label %[[SLOW:.*]], {{.*}} !nosanitize // CHECK: [[SLOW]] -// ITANIUM: call void @__cfi_slowpath(i64 7004155349499253778, i8* %[[VT2]]) {{.*}} !nosanitize -// MS: call void @__cfi_slowpath(i64 -8005289897957287421, i8* %[[VT2]]) {{.*}} !nosanitize +// ITANIUM: call void @__cfi_slowpath_diag(i64 7004155349499253778, i8* %[[VT2]], {{.*}}) {{.*}} !nosanitize +// MS: call void @__cfi_slowpath_diag(i64 -8005289897957287421, i8* %[[VT2]], {{.*}}) {{.*}} !nosanitize // CHECK: br label %[[CONT]], !nosanitize // CHECK: [[CONT]] // CHECK: call void %{{.*}}(%struct.A* %{{.*}}) Index: test/CodeGen/cfi-icall-cross-dso.c === --- test/CodeGen/cfi-icall-cross-dso.c +++ test/CodeGen/cfi-icall-cross-dso.c @@ -1,5 +1,30 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s -// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK --check-prefix=CHECK-DIAG \ +// RUN: --check-prefix=ITANIUM --check-prefix=ITANIUM-DIAG \ +// RUN: %s + +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -fsanitize-trap=cfi-icall \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK \ +// RUN: --check-prefix=ITANIUM --check-prefix=ITANIUM-TRAP \ +// RUN: %s + +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK --check-prefix=CHECK-DIAG \ +// RUN: --check-prefix=MS --check-prefix=MS-DIAG \ +// RUN: %s + +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -fsanitize-trap=cfi-icall \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK \ +// RUN: --check-prefix=MS --check-prefix=MS-TRAP \ +// RUN: %s void caller(void (*f)()) { f(); @@ -19,11 +44,18 @@ inline void foo()
Re: [PATCH] D15699: [cfi] Cross-DSO CFI diagnostic mode (clang part)
eugenis added a comment. ping Repository: rL LLVM http://reviews.llvm.org/D15699 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15699: [cfi] Cross-DSO CFI diagnostic mode (clang part)
eugenis updated this revision to Diff 45920. Repository: rL LLVM http://reviews.llvm.org/D15699 Files: lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/Driver/Tools.cpp test/CodeGen/cfi-check-fail.c test/CodeGen/cfi-icall-cross-dso.c test/CodeGenCXX/cfi-cross-dso.cpp test/CodeGenCXX/cfi-vcall.cpp Index: test/CodeGenCXX/cfi-vcall.cpp === --- test/CodeGenCXX/cfi-vcall.cpp +++ test/CodeGenCXX/cfi-vcall.cpp @@ -55,7 +55,7 @@ // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}cfi-vcall.cpp\00", align 1 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" } -// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8 } { { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]], i8 0 } +// DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }* } { i8 0, { [{{.*}} x i8]*, i32, i32 } { [{{.*}} x i8]* @[[SRC]], i32 [[@LINE+21]], i32 3 }, { i16, i16, [4 x i8] }* @[[TYPE]] } // ITANIUM: define void @_Z2afP1A // MS: define void @"\01?af@@YAXPEAUA@@@Z" @@ -69,9 +69,9 @@ // NDIAG-NEXT: call void @llvm.trap() // NDIAG-NEXT: unreachable // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint i8* [[VT]] to i64 - // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_bad_type_abort(i8* bitcast ({{.*}} @[[BADTYPESTATIC]] to i8*), i64 [[VTINT]]) + // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) // DIAG-ABORT-NEXT: unreachable - // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_bad_type(i8* bitcast ({{.*}} @[[BADTYPESTATIC]] to i8*), i64 [[VTINT]]) + // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(i8* getelementptr inbounds ({{.*}} @[[BADTYPESTATIC]], i32 0, i32 0), i64 [[VTINT]]) // DIAG-RECOVER-NEXT: br label %[[CONTBB]] // CHECK: [[CONTBB]] Index: test/CodeGenCXX/cfi-cross-dso.cpp === --- test/CodeGenCXX/cfi-cross-dso.cpp +++ test/CodeGenCXX/cfi-cross-dso.cpp @@ -34,8 +34,8 @@ // MS: %[[TEST:.*]] = call i1 @llvm.bitset.test(i8* %[[VT2]], metadata !"?AUA@@"), !nosanitize // CHECK: br i1 %[[TEST]], label %[[CONT:.*]], label %[[SLOW:.*]], {{.*}} !nosanitize // CHECK: [[SLOW]] -// ITANIUM: call void @__cfi_slowpath(i64 7004155349499253778, i8* %[[VT2]]) {{.*}} !nosanitize -// MS: call void @__cfi_slowpath(i64 -8005289897957287421, i8* %[[VT2]]) {{.*}} !nosanitize +// ITANIUM: call void @__cfi_slowpath_diag(i64 7004155349499253778, i8* %[[VT2]], {{.*}}) {{.*}} !nosanitize +// MS: call void @__cfi_slowpath_diag(i64 -8005289897957287421, i8* %[[VT2]], {{.*}}) {{.*}} !nosanitize // CHECK: br label %[[CONT]], !nosanitize // CHECK: [[CONT]] // CHECK: call void %{{.*}}(%struct.A* %{{.*}}) Index: test/CodeGen/cfi-icall-cross-dso.c === --- test/CodeGen/cfi-icall-cross-dso.c +++ test/CodeGen/cfi-icall-cross-dso.c @@ -1,5 +1,30 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s -// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK --check-prefix=CHECK-DIAG \ +// RUN: --check-prefix=ITANIUM --check-prefix=ITANIUM-DIAG \ +// RUN: %s + +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -fsanitize-trap=cfi-icall \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK \ +// RUN: --check-prefix=ITANIUM --check-prefix=ITANIUM-TRAP \ +// RUN: %s + +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK --check-prefix=CHECK-DIAG \ +// RUN: --check-prefix=MS --check-prefix=MS-DIAG \ +// RUN: %s + +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 \ +// RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -fsanitize-trap=cfi-icall \ +// RUN: -emit-llvm -o - %s | FileCheck \ +// RUN: --check-prefix=CHECK \ +// RUN: --check-prefix=MS --check-prefix=MS-TRAP \ +// RUN: %s void caller(void (*f)()) { f(); @@ -19,11 +44,18 @@ inline void foo()
Re: [PATCH] D15699: [cfi] Cross-DSO CFI diagnostic mode (clang part)
eugenis added inline comments. Comment at: test/CodeGen/cfi-check-fail.c:18 @@ +17,3 @@ +// CHECK: [[TRAP]] +// CHECK-NEXT: call void @llvm.trap() +// CHECK-NEXT: unreachable Right. It fails. I've removed the ":" after all label names. Repository: rL LLVM http://reviews.llvm.org/D15699 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r258745 - [cfi] Cross-DSO CFI diagnostic mode (clang part)
Author: eugenis Date: Mon Jan 25 17:34:52 2016 New Revision: 258745 URL: http://llvm.org/viewvc/llvm-project?rev=258745=rev Log: [cfi] Cross-DSO CFI diagnostic mode (clang part) * Runtime diagnostic data for cfi-icall changed to match the rest of cfi checks * Layout of all CFI diagnostic data changed to put Kind at the beginning. There is no ABI stability promise yet. * Call cfi_slowpath_diag instead of cfi_slowpath when needed. * Emit __cfi_check_fail function, which dispatches a CFI check faliure according to trap/recover settings of the current module. * A tiny driver change to match the way the new handlers are done in compiler-rt. Added: cfe/trunk/test/CodeGen/cfi-check-fail.c Modified: cfe/trunk/lib/CodeGen/CGClass.cpp cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/CodeGen/cfi-icall-cross-dso.c cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp cfe/trunk/test/CodeGenCXX/cfi-vcall.cpp Modified: cfe/trunk/lib/CodeGen/CGClass.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=258745=258744=258745=diff == --- cfe/trunk/lib/CodeGen/CGClass.cpp (original) +++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Jan 25 17:34:52 2016 @@ -2566,6 +2566,8 @@ void CodeGenFunction::EmitVTablePtrCheck case CFITCK_UnrelatedCast: SSK = llvm::SanStat_CFI_UnrelatedCast; break; + case CFITCK_ICall: +llvm_unreachable("not expecting CFITCK_ICall"); } EmitSanitizerStatReport(SSK); @@ -2578,13 +2580,6 @@ void CodeGenFunction::EmitVTablePtrCheck Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::bitset_test), {CastedVTable, BitSetName}); - if (CGM.getCodeGenOpts().SanitizeCfiCrossDso) { -if (auto TypeId = CGM.CreateCfiIdForTypeMetadata(MD)) { - EmitCfiSlowPathCheck(BitSetTest, TypeId, CastedVTable); - return; -} - } - SanitizerMask M; switch (TCK) { case CFITCK_VCall: @@ -2599,15 +2594,23 @@ void CodeGenFunction::EmitVTablePtrCheck case CFITCK_UnrelatedCast: M = SanitizerKind::CFIUnrelatedCast; break; + case CFITCK_ICall: +llvm_unreachable("not expecting CFITCK_ICall"); } llvm::Constant *StaticData[] = { + llvm::ConstantInt::get(Int8Ty, TCK), EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(QualType(RD->getTypeForDecl(), 0)), - llvm::ConstantInt::get(Int8Ty, TCK), }; - EmitCheck(std::make_pair(BitSetTest, M), "cfi_bad_type", StaticData, -CastedVTable); + + auto TypeId = CGM.CreateCfiIdForTypeMetadata(MD); + if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && TypeId) { +EmitCfiSlowPathCheck(M, BitSetTest, TypeId, CastedVTable, StaticData); + } else { +EmitCheck(std::make_pair(BitSetTest, M), "cfi_check_fail", StaticData, + CastedVTable); + } } // FIXME: Ideally Expr::IgnoreParenNoopCasts should do this, but it doesn't do Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=258745=258744=258745=diff == --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Jan 25 17:34:52 2016 @@ -578,7 +578,7 @@ void CodeGenFunction::EmitTypeCheck(Type if (Checks.size() > 0) { llvm::Constant *StaticData[] = { - EmitCheckSourceLocation(Loc), + EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(Ty), llvm::ConstantInt::get(SizeTy, AlignVal), llvm::ConstantInt::get(Int8Ty, TCK) @@ -2466,12 +2466,16 @@ void CodeGenFunction::EmitCheck( assert(JointCond); CheckRecoverableKind RecoverKind = getRecoverableKind(Checked[0].second); - assert(SanOpts.has(Checked[0].second)); + // In cross-DSO CFI mode this code is used to generate __cfi_check_fail, which + // includes all checks, even those that are not in SanOpts. + assert(CGM.getCodeGenOpts().SanitizeCfiCrossDso || + SanOpts.has(Checked[0].second)); #ifndef NDEBUG for (int i = 1, n = Checked.size(); i < n; ++i) { assert(RecoverKind == getRecoverableKind(Checked[i].second) && "All recoverable kinds in a single check must be same!"); -assert(SanOpts.has(Checked[i].second)); +assert(CGM.getCodeGenOpts().SanitizeCfiCrossDso || + SanOpts.has(Checked[i].second)); } #endif @@ -2485,24 +2489,26 @@ void CodeGenFunction::EmitCheck( Branch->setMetadata(llvm::LLVMContext::MD_prof, Node); EmitBlock(Handlers); - // Emit handler arguments and create handler function type. - llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs); - auto *InfoPtr = - new llvm::GlobalVariable(CGM.getModule(), Info->getType(), false, -
Re: [PATCH] D15699: [cfi] Cross-DSO CFI diagnostic mode (clang part)
eugenis closed this revision. eugenis added a comment. Thanks! Committed as http://reviews.llvm.org/rL258745 Repository: rL LLVM http://reviews.llvm.org/D15699 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r258749 - Fix use of constexpr std::pair that's not in C++11.
Author: eugenis Date: Mon Jan 25 17:45:37 2016 New Revision: 258749 URL: http://llvm.org/viewvc/llvm-project?rev=258749=rev Log: Fix use of constexpr std::pair that's not in C++11. Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=258749=258748=258749=diff == --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Jan 25 17:45:37 2016 @@ -2636,7 +2636,7 @@ void CodeGenFunction::EmitCfiCheckFail() Address CheckKindAddr(V, getIntAlign()); llvm::Value *CheckKind = Builder.CreateLoad(CheckKindAddr); - constexpr std::pairCheckKinds[] = { + const std::pair CheckKinds[] = { {CFITCK_VCall, SanitizerKind::CFIVCall}, {CFITCK_NVCall, SanitizerKind::CFINVCall}, {CFITCK_DerivedCast, SanitizerKind::CFIDerivedCast}, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r258596 - [cfi] Do not emit bit set entry for available_externally vtables.
Author: eugenis Date: Fri Jan 22 19:20:18 2016 New Revision: 258596 URL: http://llvm.org/viewvc/llvm-project?rev=258596=rev Log: [cfi] Do not emit bit set entry for available_externally vtables. In the Itanium ABI, vtable may be emitted speculatively as an available_externally global. Such vtable may not be present at the link time and should not have a corresponding CFI bit set entry. Added: cfe/trunk/test/CodeGenCXX/cfi-speculative-vtable.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=258596=258595=258596=diff == --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Fri Jan 22 19:20:18 2016 @@ -1496,7 +1496,8 @@ void ItaniumCXXABI::emitVTableDefinition DC->getParent()->isTranslationUnit()) EmitFundamentalRTTIDescriptors(); - CGM.EmitVTableBitSetEntries(VTable, VTLayout); + if (!VTable->isDeclarationForLinker()) +CGM.EmitVTableBitSetEntries(VTable, VTLayout); } bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField( Added: cfe/trunk/test/CodeGenCXX/cfi-speculative-vtable.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cfi-speculative-vtable.cpp?rev=258596=auto == --- cfe/trunk/test/CodeGenCXX/cfi-speculative-vtable.cpp (added) +++ cfe/trunk/test/CodeGenCXX/cfi-speculative-vtable.cpp Fri Jan 22 19:20:18 2016 @@ -0,0 +1,14 @@ +// Test that we don't emit a bit set entry for a speculative (available_externally) vtable. +// This does not happen in the Microsoft ABI. +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck %s + +class A { + public: + virtual ~A(); +}; + +A a; + +// CHECK: @_ZTV1A ={{.*}} available_externally +// CHECK-NOT: !{{.*}} = !{!{{.*}}, [4 x i8*]* @_ZTV1A, i64 16} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D17360: [cfi] Fix handling of sanitize trap/recover flags in the cross-DSO CFI mode.
eugenis created this revision. eugenis added reviewers: pcc, krasin. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. In the cross-DSO CFI mode a module may be asked to handle any type of CFI error, even if the module itself is not checked for that type of error. Therefore, trap/recover flags should be preserved all CFI checkers and not just for the ones that are enabled. This fixes a linker error caused by the missing cfi_diag runtime library with certain combinations of CFI flags (see the new test case). Repository: rL LLVM http://reviews.llvm.org/D17360 Files: lib/Driver/SanitizerArgs.cpp test/Driver/fsanitize.c Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -272,6 +272,21 @@ // CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc // CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso +// In the non-cross-dso CFI mode, -fsanitize-trap only appears for enabled CFI checkers. +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi-vcall -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-VCALL-TRAP +// CHECK-CFI-VCALL-TRAP: "-fsanitize=cfi-vcall" "-fsanitize-trap=cfi-vcall" + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi-vcall -fno-sanitize-trap=cfi-vcall -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-VCALL-NO-TRAP +// CHECK-CFI-VCALL-NO-TRAP: "-fsanitize=cfi-vcall" +// CHECK-CFI-VCALL-NO-TRAP-NOT: -fsanitize-trap= + +// In the cross-dso CFI mode, -fsanitize-trap appears for all CFI checkers. +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi-vcall -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO-VCALL-TRAP +// CHECK-CFI-CROSS-DSO-VCALL-TRAP: "-fsanitize=cfi-vcall" "-fsanitize-trap=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall" + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi-vcall -fno-sanitize-trap=cfi-vcall -fsanitize-cfi-cross-dso -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-CROSS-DSO-VCALL-NO-TRAP +// CHECK-CFI-CROSS-DSO-VCALL-NO-TRAP: "-fsanitize=cfi-vcall" "-fsanitize-trap=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall" + // RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -fsanitize-stats -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-STATS // CHECK-CFI-STATS: -fsanitize-stats Index: lib/Driver/SanitizerArgs.cpp === --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -166,11 +166,11 @@ } bool SanitizerArgs::needsCfiRt() const { - return !(Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso; + return !(CFI & ~TrapSanitizers.Mask) && CfiCrossDso; } bool SanitizerArgs::needsCfiDiagRt() const { - return (Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso; + return (CFI & ~TrapSanitizers.Mask) && CfiCrossDso; } bool SanitizerArgs::requiresPIE() const { @@ -361,10 +361,27 @@ << DeprecatedReplacement; } } - RecoverableKinds &= Kinds; - RecoverableKinds &= ~Unrecoverable; - TrappingKinds &= Kinds; + if (AllAddedKinds & CFI) { +CfiCrossDso = Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso, + options::OPT_fno_sanitize_cfi_cross_dso, false); +// Without PIE, external function address may resolve to a PLT record, which +// can not be verified by the target module. +NeedPIE |= CfiCrossDso; + } + + // In the cross-DSO CFI mode a module may be asked to handle any type of CFI + // error, even if the module itself is not checked for that type of error. + // Therefore, trap/recover flags should be preserved all CFI checkers. + if (CfiCrossDso) { +TrappingKinds &= (Kinds | CFI); +RecoverableKinds &= (Kinds | CFI); + } else { +TrappingKinds &= Kinds; +RecoverableKinds &= Kinds; + } + + RecoverableKinds &= ~Unrecoverable; // Setup blacklist files. // Add default blacklist from resource directory. @@ -424,14 +441,6 @@ TC.getTriple().getArch() == llvm::Triple::x86_64); } - if (AllAddedKinds & CFI) { -CfiCrossDso = Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso, - options::OPT_fno_sanitize_cfi_cross_dso, false); -// Without PIE, external function address may resolve to a PLT record, which -// can not be verified by the target module. -NeedPIE |= CfiCrossDso; - } - Stats = Args.hasFlag(options::OPT_fsanitize_stats, options::OPT_fno_sanitize_stats, false); Index: test/Driver/fsanitize.c === --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -272,6 +272,21 @@ // CHECK-CFI-NO-CROSS-DSO: -emit-llvm-bc // CHECK-CFI-NO-CROSS-DSO-NOT: -fsanitize-cfi-cross-dso +// In the
Re: [PATCH] D17360: [cfi] Fix handling of sanitize trap/recover flags in the cross-DSO CFI mode.
eugenis added a comment. This lets us support the following case: module A checks vcalls and casts, with diagnostics module B checks vcalls but not casts (but it still has bitsets for vtables), with diagnostics then a cast check from module A with a target in module B should print diagnostics instead of trapping It's definitely not critical functionality, but could be nice to have, especially as it does not cost us anything. And yes, CodeGenModule::NeedAllVtablesBitSet needs to be fixed for this work. WDYT? Repository: rL LLVM http://reviews.llvm.org/D17360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D17360: [cfi] Fix handling of sanitize trap/recover flags in the cross-DSO CFI mode.
eugenis added a comment. ping Repository: rL LLVM http://reviews.llvm.org/D17360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D17360: [cfi] Fix handling of sanitize trap/recover flags in the cross-DSO CFI mode.
eugenis closed this revision. eugenis added a comment. r263180, thanks for the review! Repository: rL LLVM http://reviews.llvm.org/D17360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D17360: [cfi] Fix handling of sanitize trap/recover flags in the cross-DSO CFI mode.
eugenis added a comment. No, this is not committed. I've run dcommit in the wrong checkout and landed http://reviews.llvm.org/D17900 instead. Repository: rL LLVM http://reviews.llvm.org/D17360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D17360: [cfi] Fix handling of sanitize trap/recover flags in the cross-DSO CFI mode.
eugenis added a comment. r263578, finally Repository: rL LLVM http://reviews.llvm.org/D17360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r263578 - [cfi] Don't emit checks for disabled CFI kinds.
Author: eugenis Date: Tue Mar 15 15:19:29 2016 New Revision: 263578 URL: http://llvm.org/viewvc/llvm-project?rev=263578=rev Log: [cfi] Don't emit checks for disabled CFI kinds. In the cross-DSO CFI mode clang emits __cfi_check_fail that handles errors triggered from other modules with targets in the current module. With this change, __cfi_check_fail will handle errors for CFI kinds that are not enabled in the current module as if they have the trapping behaviour (-fsanitize-trap=...). This fixes a bug where some combinations of -fsanitize* flags may result in a link failure due to a missing sanitizer runtime library for the diagnostic calls in __cfi_check_fail. Added: cfe/trunk/test/CodeGen/cfi-check-fail2.c - copied, changed from r263574, cfe/trunk/test/CodeGen/cfi-check-fail.c Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/test/CodeGen/cfi-check-fail.c Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=263578=263577=263578=diff == --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Mar 15 15:19:29 2016 @@ -2479,16 +2479,12 @@ void CodeGenFunction::EmitCheck( assert(JointCond); CheckRecoverableKind RecoverKind = getRecoverableKind(Checked[0].second); - // In cross-DSO CFI mode this code is used to generate __cfi_check_fail, which - // includes all checks, even those that are not in SanOpts. - assert(CGM.getCodeGenOpts().SanitizeCfiCrossDso || - SanOpts.has(Checked[0].second)); + assert(SanOpts.has(Checked[0].second)); #ifndef NDEBUG for (int i = 1, n = Checked.size(); i < n; ++i) { assert(RecoverKind == getRecoverableKind(Checked[i].second) && "All recoverable kinds in a single check must be same!"); -assert(CGM.getCodeGenOpts().SanitizeCfiCrossDso || - SanOpts.has(Checked[i].second)); +assert(SanOpts.has(Checked[i].second)); } #endif @@ -2670,8 +2666,11 @@ void CodeGenFunction::EmitCfiCheckFail() SanitizerMask Mask = CheckKindMaskPair.second; llvm::Value *Cond = Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(Int8Ty, Kind)); -EmitCheck(std::make_pair(Cond, Mask), "cfi_check_fail", {}, - {Data, Addr, ValidVtable}); +if (CGM.getLangOpts().Sanitize.has(Mask)) + EmitCheck(std::make_pair(Cond, Mask), "cfi_check_fail", {}, +{Data, Addr, ValidVtable}); +else + EmitTrapCheck(Cond); } FinishFunction(); Modified: cfe/trunk/test/CodeGen/cfi-check-fail.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail.c?rev=263578=263577=263578=diff == --- cfe/trunk/test/CodeGen/cfi-check-fail.c (original) +++ cfe/trunk/test/CodeGen/cfi-check-fail.c Tue Mar 15 15:19:29 2016 @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \ +// RUN: -fsanitize=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \ // RUN: -fsanitize-trap=cfi-icall,cfi-nvcall -fsanitize-recover=cfi-vcall,cfi-unrelated-cast \ // RUN: -emit-llvm -o - %s | FileCheck %s Copied: cfe/trunk/test/CodeGen/cfi-check-fail2.c (from r263574, cfe/trunk/test/CodeGen/cfi-check-fail.c) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail2.c?p2=cfe/trunk/test/CodeGen/cfi-check-fail2.c=cfe/trunk/test/CodeGen/cfi-check-fail.c=263574=263578=263578=diff == --- cfe/trunk/test/CodeGen/cfi-check-fail.c (original) +++ cfe/trunk/test/CodeGen/cfi-check-fail2.c Tue Mar 15 15:19:29 2016 @@ -1,5 +1,6 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \ -// RUN: -fsanitize-trap=cfi-icall,cfi-nvcall -fsanitize-recover=cfi-vcall,cfi-unrelated-cast \ +// __cfi_check_fail codegen when not all CFI checkers are enabled. +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \ +// RUN: -fsanitize=cfi-vcall \ // RUN: -emit-llvm -o - %s | FileCheck %s void caller(void (*f)()) { @@ -30,8 +31,8 @@ void caller(void (*f)()) { // CHECK: [[HANDLE0]]: // CHECK: %[[DATA0:.*]] = ptrtoint i8* %[[DATA]] to i64, // CHECK: %[[ADDR0:.*]] = ptrtoint i8* %[[ADDR]] to i64, -// CHECK: call void @__ubsan_handle_cfi_check_fail(i64 %[[DATA0]], i64 %[[ADDR0]], i64 %[[VTVALID]]) -// CHECK: br label %[[CONT1]] +// CHECK: call void @__ubsan_handle_cfi_check_fail_abort(i64 %[[DATA0]], i64 %[[ADDR0]], i64 %[[VTVALID]]) +// CHECK: unreachable // CHECK: [[CONT1]]: // CHECK: %[[NOT_1:.*]] = icmp ne i8 %[[KIND]], 1 @@ -43,23 +44,19 @@ void caller(void (*f)()) { // CHECK:
[PATCH] D18107: Disable CFI checks in std::addressof.
eugenis created this revision. eugenis added a reviewer: EricWF. eugenis added a subscriber: cfe-commits. eugenis set the repository for this revision to rL LLVM. std::addressof may be used on a storage of an object before the start of its lifetime (see std::allocate_shared for example). CFI flags the C-style cast as invalid in that case. Repository: rL LLVM http://reviews.llvm.org/D18107 Files: include/type_traits Index: include/type_traits === --- include/type_traits +++ include/type_traits @@ -399,7 +399,7 @@ // addressof template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY _Tp* addressof(_Tp& __x) _NOEXCEPT { Index: include/type_traits === --- include/type_traits +++ include/type_traits @@ -399,7 +399,7 @@ // addressof template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY _Tp* addressof(_Tp& __x) _NOEXCEPT { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r263310 - Disable CFI checks in std::addressof.
Author: eugenis Date: Fri Mar 11 17:50:57 2016 New Revision: 263310 URL: http://llvm.org/viewvc/llvm-project?rev=263310=rev Log: Disable CFI checks in std::addressof. std::addressof may be used on a storage of an object before the start of its lifetime (see std::allocate_shared for example). CFI flags the C-style cast as invalid in that case. Modified: libcxx/trunk/include/type_traits Modified: libcxx/trunk/include/type_traits URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=263310=263309=263310=diff == --- libcxx/trunk/include/type_traits (original) +++ libcxx/trunk/include/type_traits Fri Mar 11 17:50:57 2016 @@ -399,7 +399,7 @@ template us // addressof template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY _Tp* addressof(_Tp& __x) _NOEXCEPT { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18107: Disable CFI checks in std::addressof.
eugenis closed this revision. eugenis added a comment. r263310 Thanks! Repository: rL LLVM http://reviews.llvm.org/D18107 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16538: [cc1as] Add MCTargetOptions argument to createAsmBackend
eugenis added inline comments. Comment at: tools/driver/cc1as_main.cpp:413-416 @@ -412,6 +414,6 @@ // FIXME: init MCTargetOptions from sanitizer flags here. MCTargetOptions Options; std::unique_ptr TAP( TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options)); if (!TAP) dsanders wrote: > @eugenis: Do you know what needs to be done for this FIXME? I think this is about allowing -fsanitize=address as a cc1as flag to enable asan instrumentation in standalone assembly files. Currently it is only supported in inline assembly. http://reviews.llvm.org/D16538 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r266095 - Stricter checks in the stack-protector codegen test.
Author: eugenis Date: Tue Apr 12 12:51:59 2016 New Revision: 266095 URL: http://llvm.org/viewvc/llvm-project?rev=266095=rev Log: Stricter checks in the stack-protector codegen test. Modified: cfe/trunk/test/CodeGen/stack-protector.c Modified: cfe/trunk/test/CodeGen/stack-protector.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/stack-protector.c?rev=266095=266094=266095=diff == --- cfe/trunk/test/CodeGen/stack-protector.c (original) +++ cfe/trunk/test/CodeGen/stack-protector.c Tue Apr 12 12:51:59 2016 @@ -23,13 +23,13 @@ void test1(const char *msg) { } // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp -// SSP: attributes #[[A]] = {{.*}} ssp +// SSP: attributes #[[A]] = {{.*}} ssp{{ }} // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong // SSPREQ: attributes #[[A]] = {{.*}} sspreq // SAFESTACK-NOSSP: attributes #[[A]] = {{.*}} safestack // SAFESTACK-NOSSP-NOT: ssp -// SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp +// SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }} // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits