This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Add a slim Scudo shared runtime
AbandonedPublic

Authored by cryptoad on Mar 15 2018, 10:03 AM.

Details

Summary

So I am actually not sure what would be the prefered way to do that from a
Sanitizer perspective, so here is one way that works, but feel free to point me
in another direction.

Fuchsia would like a standalone slim Scudo shared library, without C++
dependencies and with as few extras as possible. Right now, we bundle RTUBsan
because we want to cover the case -fsanitize=scudo,undefined, which has some
C++ runtime dependencies. So this new slim Scudo runtime will be UBSan free.

But then the other issue is that there is a whole lot of public functions that
are exported by default in sanitizer_common that pull in stuff like the
symbolizer or stacktraces modules that Scudo has no use for. This ends up
pulling in the internal allocator which has a 512kB memory footprint in the
bss section for example. So I defined a minimal set of files from
sanitizer_common needed by Scudo to get rid of all the extras.

The last thing was to override __sanitizer_sandbox_on_notify which was
pulling in the symbolizer has well.

This would also allow to add nostdlib++ and nostdinc++ to the minimal
runtime.

Here are a few binary sizes with different compilations options:

  • a build with gcc: lib/clang/7.0.0/lib/linux/libclang_rt.scudo-x86_64.so 2777112 lib/clang/7.0.0/lib/linux/libclang_rt.scudo_minimal-x86_64.so 1608024
  • a build with clang: lib/clang/7.0.0/lib/linux/libclang_rt.scudo-x86_64.so 469392 lib/clang/7.0.0/lib/linux/libclang_rt.scudo_minimal-x86_64.so 238432

Let me know what you think, or if there is another way to achieve this.

Event Timeline

cryptoad created this revision.Mar 15 2018, 10:03 AM
Herald added subscribers: Restricted Project, llvm-commits, delcypher and 2 others. · View Herald TranscriptMar 15 2018, 10:03 AM
cryptoad added inline comments.Mar 15 2018, 10:10 AM
lib/sanitizer_common/CMakeLists.txt
234

So this is not entirely correct as this should probably be SCUDO_SUPPORTED_ARCH, but I am not sure I want to mix in both.

eugenis added a subscriber: pcc.Mar 16 2018, 11:41 AM
eugenis added inline comments.
lib/sanitizer_common/CMakeLists.txt
99

That's unfortunate that this is not a subset of any other source list. I'm worried that people will forget to update it, and would not know whether a new file belongs here or not. It's probably OK as long as scudo_minimal is built by default in compiler-rt.

AFAIR @pcc mentioned that _libcdep / _nolibc distinction can be deprecated. Is that true? If those are merged into a single source list, would this new SCUDO list be a subset of it?

234

This looks fine to me - this library should be buildable for all of $SANITIZER_COMMON_SUPPORTED_ARCH.

lib/scudo/scudo_override.cpp
22

#include "sanitizer_common/sanitizer_interface_internal.h" ?

cryptoad added inline comments.Mar 16 2018, 12:23 PM
lib/sanitizer_common/CMakeLists.txt
99

I am currently trying to do some splits locally, which would make more sense that this version.
The coverage related files can end up in their own RTSanitizerCommonCoverage rule so far successfully.
Right now I am battling with the symbolizer/stacktrace files that are more intertwined, trying to have them in a RTSanitizerCommonSymbolizer rule.
As far I can see, Safestack is the only consummer of the nolibc part, and is also part of the headache.

lib/scudo/scudo_override.cpp
22

IIRC I tried but said include defines __sanitizer_sandbox_on_notify as weak and it doesn't override the the function.
In my local copy I ended up with a void *args since it's extern "C" anyway.

Here is a general idea for a split Coverage & Symbolizer/StackTraces: https://reviews.llvm.org/D44578
Still some minor changes to do for the less common sanitizers but tests for the main ones pass (on Linux).

cryptoad abandoned this revision.Mar 20 2018, 9:57 AM

Abandoning this, moving towards a split of Coverage & Symbolizer/StackTrace in SanitizerCommon that would end up with the same effect wrt Scudo.