[compiler-rt] r366186 - Finish "Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO"

Ilya Biryukov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 02:07:34 PDT 2019


Hi Stephan,

Is there a more principled way to use sanitizer_platform.h from the test?

We are running clang tests in a distributed environment and don't have a
full source checkout when running the tests.
One way to make it work for us is to make the test depend on the build
target producing the headers and configure the compiler being run (by
passing the -I flag or something similar).


On Tue, Jul 16, 2019 at 8:23 AM Stephan Bergmann via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: sberg
> Date: Mon Jul 15 23:23:27 2019
> New Revision: 366186
>
> URL: http://llvm.org/viewvc/llvm-project?rev=366186&view=rev
> Log:
> Finish "Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO"
>
> i.e., recent 5745eccef54ddd3caca278d1d292a88b2281528b:
>
> * Bump the function_type_mismatch handler version, as its signature has
> changed.
>
> * The function_type_mismatch handler can return successfully now, so
>   SanitizerKind::Function must be AlwaysRecoverable (like for
>   SanitizerKind::Vptr).
>
> * But the minimal runtime would still unconditionally treat a call to the
>   function_type_mismatch handler as failure, so disallow
> -fsanitize=function in
>   combination with -fsanitize-minimal-runtime (like it was already done for
>   -fsanitize=vptr).
>
> * Add tests.
>
> Differential Revision: https://reviews.llvm.org/D61479
>
> Modified:
>     compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc
>     compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.h
>     compiler-rt/trunk/lib/ubsan/ubsan_interface.inc
>     compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp
>
> Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc?rev=366186&r1=366185&r2=366186&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc (original)
> +++ compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc Mon Jul 15 23:23:27
> 2019
> @@ -185,18 +185,17 @@ static bool handleFunctionTypeMismatch(F
>    return true;
>  }
>
> -void __ubsan_handle_function_type_mismatch(FunctionTypeMismatchData *Data,
> -                                           ValueHandle Function,
> -                                           ValueHandle calleeRTTI,
> -                                           ValueHandle fnRTTI) {
> +void __ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData
> *Data,
> +                                              ValueHandle Function,
> +                                              ValueHandle calleeRTTI,
> +                                              ValueHandle fnRTTI) {
>    GET_REPORT_OPTIONS(false);
>    handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI, Opts);
>  }
>
> -void __ubsan_handle_function_type_mismatch_abort(FunctionTypeMismatchData
> *Data,
> -                                                 ValueHandle Function,
> -                                                 ValueHandle calleeRTTI,
> -                                                 ValueHandle fnRTTI) {
> +void __ubsan_handle_function_type_mismatch_v1_abort(
> +    FunctionTypeMismatchData *Data, ValueHandle Function,
> +    ValueHandle calleeRTTI, ValueHandle fnRTTI) {
>    GET_REPORT_OPTIONS(true);
>    if (handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI,
> Opts))
>      Die();
>
> Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.h?rev=366186&r1=366185&r2=366186&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.h (original)
> +++ compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.h Mon Jul 15 23:23:27
> 2019
> @@ -40,14 +40,15 @@ struct FunctionTypeMismatchData {
>  };
>
>  extern "C" SANITIZER_INTERFACE_ATTRIBUTE void
> -__ubsan_handle_function_type_mismatch(FunctionTypeMismatchData *Data,
> -                                      ValueHandle Val, ValueHandle
> calleeRTTI,
> -                                      ValueHandle fnRTTI);
> +__ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData *Data,
> +                                         ValueHandle Val,
> +                                         ValueHandle calleeRTTI,
> +                                         ValueHandle fnRTTI);
>  extern "C" SANITIZER_INTERFACE_ATTRIBUTE void
> -__ubsan_handle_function_type_mismatch_abort(FunctionTypeMismatchData
> *Data,
> -                                            ValueHandle Val,
> -                                            ValueHandle calleeRTTI,
> -                                            ValueHandle fnRTTI);
> +__ubsan_handle_function_type_mismatch_v1_abort(FunctionTypeMismatchData
> *Data,
> +                                               ValueHandle Val,
> +                                               ValueHandle calleeRTTI,
> +                                               ValueHandle fnRTTI);
>  }
>
>  #endif // UBSAN_HANDLERS_H
>
> Modified: compiler-rt/trunk/lib/ubsan/ubsan_interface.inc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_interface.inc?rev=366186&r1=366185&r2=366186&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/ubsan/ubsan_interface.inc (original)
> +++ compiler-rt/trunk/lib/ubsan/ubsan_interface.inc Mon Jul 15 23:23:27
> 2019
> @@ -21,8 +21,8 @@ INTERFACE_FUNCTION(__ubsan_handle_dynami
>  INTERFACE_FUNCTION(__ubsan_handle_dynamic_type_cache_miss_abort)
>  INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow)
>  INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow_abort)
> -INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch)
> -INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_abort)
> +INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1)
> +INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1_abort)
>  INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion)
>  INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion_abort)
>  INTERFACE_FUNCTION(__ubsan_handle_invalid_builtin)
>
> Modified:
> compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp?rev=366186&r1=366185&r2=366186&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp
> (original)
> +++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp
> Mon Jul 15 23:23:27 2019
> @@ -1,11 +1,53 @@
> -// RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -o %t
> -// RUN: %run %t 2>&1 | FileCheck %s
> +// RUN: %clangxx -DDETERMINE_UNIQUE %s -o %t-unique
> +// RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -DSHARED_LIB
> -fPIC -shared -o %t-so.so
> +// RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -o %t %t-so.so
> +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK $(%run %t-unique
> UNIQUE)
>  // Verify that we can disable symbolization if needed:
> -// RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s
> --check-prefix=NOSYM
> +// RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s
> --check-prefix=NOSYM $(%run %t-unique NOSYM-UNIQUE)
>  // XFAIL: windows-msvc
>  // Unsupported function flag
>  // UNSUPPORTED: openbsd
>
> +#ifdef DETERMINE_UNIQUE
> +
> +#include <iostream>
> +
> +#include "../../../../../lib/sanitizer_common/sanitizer_platform.h"
> +
> +int main(int, char **argv) {
> +  if (!SANITIZER_NON_UNIQUE_TYPEINFO)
> +    std::cout << "--check-prefix=" << argv[1];
> +}
> +
> +#else
> +
> +struct Shared {};
> +using FnShared = void (*)(Shared *);
> +FnShared getShared();
> +
> +struct __attribute__((visibility("hidden"))) Hidden {};
> +using FnHidden = void (*)(Hidden *);
> +FnHidden getHidden();
> +
> +namespace {
> +struct Private {};
> +} // namespace
> +using FnPrivate = void (*)(void *);
> +FnPrivate getPrivate();
> +
> +#ifdef SHARED_LIB
> +
> +void fnShared(Shared *) {}
> +FnShared getShared() { return fnShared; }
> +
> +void fnHidden(Hidden *) {}
> +FnHidden getHidden() { return fnHidden; }
> +
> +void fnPrivate(Private *) {}
> +FnPrivate getPrivate() { return reinterpret_cast<FnPrivate>(fnPrivate); }
> +
> +#else
> +
>  #include <stdint.h>
>
>  void f() {}
> @@ -64,12 +106,31 @@ void check_noexcept_calls() {
>    p2(0);
>  }
>
> +void check_cross_dso() {
> +  getShared()(nullptr);
> +
> +  // UNIQUE: function.cpp:[[@LINE+2]]:3: runtime error: call to function
> fnHidden(Hidden*) through pointer to incorrect function type 'void
> (*)(Hidden *)'
> +  // NOSYM-UNIQUE: function.cpp:[[@LINE+1]]:3: runtime error: call to
> function (unknown) through pointer to incorrect function type 'void
> (*)(Hidden *)'
> +  getHidden()(nullptr);
> +
> +  // TODO: Unlike GCC, Clang fails to prefix the typeinfo name for the
> function
> +  // type with "*", so this erroneously only fails for "*UNIQUE":
> +  // UNIQUE: function.cpp:[[@LINE+2]]:3: runtime error: call to function
> fnPrivate((anonymous namespace)::Private*) through pointer to incorrect
> function type 'void (*)((anonymous namespace)::Private *)'
> +  // NOSYM-UNIQUE: function.cpp:[[@LINE+1]]:3: runtime error: call to
> function (unknown) through pointer to incorrect function type 'void
> (*)((anonymous namespace)::Private *)'
> +  reinterpret_cast<void (*)(Private *)>(getPrivate())(nullptr);
> +}
> +
>  int main(void) {
>    make_valid_call();
>    make_invalid_call();
>    check_noexcept_calls();
> +  check_cross_dso();
>    // Check that no more errors will be printed.
>    // CHECK-NOT: runtime error: call to function
>    // NOSYM-NOT: runtime error: call to function
>    make_invalid_call();
>  }
> +
> +#endif
> +
> +#endif
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>


-- 
Regards,
Ilya Biryukov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190716/131f2f27/attachment.html>


More information about the llvm-commits mailing list