[PATCH] D67298: [ASan] Only run dlopen-mixed-c-cxx.c with static runtime

Jonas Hahnfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 7 06:06:49 PDT 2019


Hahnfeld added a comment.

In D67298#1662107 <https://reviews.llvm.org/D67298#1662107>, @serge-sans-paille wrote:

> > And that's what I don't understand
>
> My fault for not being clear enough. Let me elaborate the original faulty use case:
>
> You've got an application written in C, compiled with asan, that dlopens a library written in C++, linked to libstdc++
>  When the application starts, asan installs a few handler based on the loaded symbols. It used to install a handler that points to itself for `__cxa_throw` because the symbol is not present in the binary.


Apparently, this is only the case when the asan runtime is linked statically. Otherwise the dynamic runtime pulls in the full libstdc++ and installation of the handler succeeds.

> When the C++ library is loaded, it resolves `__cxa_throw` to the asan implementation instead of the libstdc++ implementation.
>  When an exception is raised, the asam handler is called (that's normal) but it doesn't fallsback to libstdc++ (because this library wasn't loaded when the handler got initialized).
> 
> The problem with current test case is that it assumes the c++ code is compiled with libstdc++, which is an invalid assumption based on your feedback.

Where does the test assume that the C++ code is linked with libstdc++? I only observed that the test passes if the asan runtime is linked to libstdc++.

> We could force clang to use libstdc++ when linking the C++ library, would that work in your situation?
> 
>   - // RUN: %clangxx_asan -xc++ -shared -fPIC -o %t.so - < %s
>   + // RUN: %clangxx_asan -xc++ -stdlib=libstdc++ -shared -fPIC -o %t.so - < %s
> 
> 
> Assuming libstdc++ is available in the system?

I just tested this change and it doesn't work (at least for dynamic runtime). This matches my theory that the test expects static runtime.

Can you please try to reproduce the failing test in `check-asan-dynamic` on your end? Configuring a standalone build of `compiler-rt` with `-DCOMPILER_RT_INCLUDE_TESTS=ON -DSANITIZER_CXX_ABI=libcxxabi` should be enough.


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

https://reviews.llvm.org/D67298





More information about the llvm-commits mailing list