Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add address and undefined sanitizers to github action #417

Merged
merged 8 commits into from
Aug 11, 2021

Conversation

mo-xiaoming
Copy link
Contributor

Besides being ugly, there are few things to note

  1. Currently leak detection is disabled
  2. Has to add something like -Og to debug flags, otherwise, get warning _FORTIFY_SOURCE requires compiling with optimization (-O). This is a long standing nix/gcc bug GCC has unwanted flags NixOS/nixpkgs#18995
  3. Default added to path, otherwise, nix generates something like hobbesPackages/gcc-8/llvm-9//hobbes. Don't know how to get ride of //, so a Default added
  4. Adding sanitizers make build slow, and Release build with sanitizer and debug symbols takes forever to build. So there is only one active(gcc8, llvm11?) version is checked by sanitizers

@mo-xiaoming
Copy link
Contributor Author

It just proved its value, a null pointer reference was detected

/nix/store/rnh1x6pijwlmk14cy5jnyl5v51mc72wi-gcc-8.4.0/include/c++/8.4.0/bits/stl_iterator.h:797:17: runtime error: reference binding to null pointer of type 'const unsigned char'
    #0 0x952bef in __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const /nix/store/rnh1x6pijwlmk14cy5jnyl5v51mc72wi-gcc-8.4.0/include/c++/8.4.0/bits/stl_iterator.h:797
    #1 0x952bef in void hobbes::fregion::writes<__gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > >(hobbes::fregion::imagefile*, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >) ../include/hobbes/fregion.H:265
    #2 0x952bef in hobbes::fregion::write(hobbes::fregion::imagefile*, std::vector<unsigned char, std::allocator<unsigned char> > const&) ../include/hobbes/fregion.H:273
    #3 0x952bef in hobbes::fregion::addBinding(hobbes::fregion::imagefile*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&, unsigned long) ../include/hobbes/fregion.H:578
    #4 0x95a4f9 in hobbes::fregion::openFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, unsigned short, unsigned short, unsigned long) ../include/hobbes/fregion.H:903
    #5 0x8e118f in hobbes::fregion::writer::writer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../include/hobbes/fregion.H:1945
    #6 0x8e118f in makeTestData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../test/Python.C:98
    #7 0x8e8c34 in test_Python_FRegion() ../test/Python.C:272
    #8 0x71650d in TestCoord::runTestGroups(Args const&) ../test/Main.C:64
    #9 0x7297f6 in main ../test/Main.C:143
    #10 0x7ffff6184dec in __libc_start_main (/nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libc.so.6+0x27dec)
    #11 0x4927d9 in _start (/build/source/build/hobbes-test+0x4927d9)

WIP

nix/overlays.nix Outdated
inherit version src meta doCheck doTarget dontStrip;
pname = "hobbes-clang-" + (toString llvmVersion) + (if sans then "-ASanAndUBSan" else "");

cmakeBuildType=(if sans then "Debug" else "Release");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a debug flag to this nix expression, you should use that instead

@smunix
Copy link
Contributor

smunix commented Aug 5, 2021

Run sanitizers with clang only (not gcc)

Copy link
Contributor

@smunix smunix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add new SAN specific package targets
  • use Clang (not GCC) only for the SAN packages

nix/overlays.nix Outdated
value = recurseIntoAttrs ({
hobbes = dbg (callPackage withCLANG { inherit llvmVersion; });
});
value = recurseIntoAttrs (builtins.listToAttrs (builtins.map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new separate SAN specific packages withSans instead. Do not add params to the existing ones

@mo-xiaoming
Copy link
Contributor Author

There are few changed in the last two commits

  1. Previous crash was caused by accessing the first element of an empty vector

    addBinding(f, ".za", bytes(), f->empty_array);

  2. test/Python.C failed on my ubuntu20.04

        Python (1 test)
      ---------------------------------------------------------
    Traceback (most recent call last):
      File "/tmp/hdb-unittest-1.py", line 14, in <module>
        f = fregion.FRegion(sys.argv[1])
      File "/home/ubuntu/hobbes-llvm11/scripts/fregion.py", line 1068, in __init__
        bind.reader = makeReader({}, bind.ty)
      File "/home/ubuntu/hobbes-llvm11/scripts/fregion.py", line 1030, in makeReader
        return TyCase(readerDisp).apply(ty)
      File "/home/ubuntu/hobbes-llvm11/scripts/fregion.py", line 247, in apply
        return self.dtors["prim"](ty)
      File "/home/ubuntu/hobbes-llvm11/scripts/fregion.py", line 1019, in <lambda>
        "prim":    lambda p:  makePrimReader(renv, p),
      File "/home/ubuntu/hobbes-llvm11/scripts/fregion.py", line 958, in makePrimReader
        raise Exception("I don't know how to decode the primitive type: " + p.name)
    Exception: I don't know how to decode the primitive type: b'bool'
        FRegion FAIL (317.155ms)
    

    include(FindPythonInterp) finds python3 on my system, but fregion.py only can handle python2 strings (bytes by default), and python3 uses unicode as default, so we can see b'bool' doesn't match 'bool'

    Migrating this script to be python3 compatible is just too much work, so I just simply force it to search python2.7

  3. enableDebugging doesn't seem to change CMAKE_BUILD_TYPE, it still use Release, which doesn't set proper flags

    diff --git a/nix/overlays.nix b/nix/overlays.nix
    index 14b1944..55f7636 100644
    --- a/nix/overlays.nix
    +++ b/nix/overlays.nix
    @@ -79,7 +79,6 @@ let
           inherit version src meta doCheck doTarget;
    
           dontStrip = true;
    -      cmakeBuildType="Debug";
           cmakeFlags = [
             "-DUSE_ASAN_AND_UBSAN:BOOL=ON"
           ];
    @@ -119,7 +118,7 @@ in {
           (llvmVersion: {
             name = "clang-" + toString llvmVersion + "-ASanAndUBSan";
             value = recurseIntoAttrs ({
    -          hobbes = dbg (callPackage withCLANGAsanAndUBSan { inherit llvmVersion; });
    +          hobbes = enableDebugging (callPackage withCLANGAsanAndUBSan { inherit llvmVersion; });
             });
           }) llvmVersions));
     }

Now CI failed on an function pointer conversion which I've seen at least a month ago, then I've not been able to reproduce it since then...

WIP

@@ -262,6 +262,9 @@ template <typename T>
}
template <typename TIter>
inline void writes(imagefile* f, TIter begin, TIter end) {
if (begin == end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

@@ -89,5 +115,11 @@ in {
value = recurseIntoAttrs ({
hobbes = dbg (callPackage withCLANG { inherit llvmVersion; });
});
}) llvmVersions)) // recurseIntoAttrs (builtins.listToAttrs (builtins.map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great, @mo-xiaoming

CMakeLists.txt Outdated Show resolved Hide resolved
.github/workflows/build.yml Outdated Show resolved Hide resolved
@smunix smunix self-requested a review August 11, 2021 19:37
@smunix smunix merged commit d3e2a51 into morganstanley:main Aug 11, 2021
@mo-xiaoming mo-xiaoming deleted the asan_ubsan branch August 11, 2021 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants