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

tarantool seems to fail to compile when ENABLE_ASAN=on is used #3070

Closed
evverx opened this issue Jan 23, 2018 · 7 comments
Closed

tarantool seems to fail to compile when ENABLE_ASAN=on is used #3070

evverx opened this issue Jan 23, 2018 · 7 comments
Labels
qa Issues related to tests or testing subsystem

Comments

@evverx
Copy link

evverx commented Jan 23, 2018

llvm-mirror/compiler-rt@0b95585 seems to have broken the code depending on __sanitizer_finish_switch_fiber having only one argument:

$ git describe
1.8.3-82-gac85d63

$ clang-5.0 --version
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

$ cmake -D ENABLE_ASAN=ON .
...

$ make
...
[ 19%] Building C object src/CMakeFiles/core.dir/fiber.c.o
/home/ubuntu/tarantool/src/fiber.c:187:2: error: too few arguments to function call, expected 3, have 1
        ASAN_FINISH_SWITCH_FIBER(asan_state);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ubuntu/tarantool/src/fiber.c:57:42: note: expanded from macro 'ASAN_FINISH_SWITCH_FIBER'
        __sanitizer_finish_switch_fiber(var_name);
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         ^
/usr/local/lib/clang/5.0.0/include/sanitizer/common_interface_defs.h:184:3: note: '__sanitizer_finish_switch_fiber' declared here
  void __sanitizer_finish_switch_fiber(void *fake_stack_save,
  ^
/home/ubuntu/tarantool/src/fiber.c:427:2: error: too few arguments to function call, expected 3, have 1
        ASAN_FINISH_SWITCH_FIBER(asan_state);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ubuntu/tarantool/src/fiber.c:57:42: note: expanded from macro 'ASAN_FINISH_SWITCH_FIBER'
        __sanitizer_finish_switch_fiber(var_name);
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         ^
/usr/local/lib/clang/5.0.0/include/sanitizer/common_interface_defs.h:184:3: note: '__sanitizer_finish_switch_fiber' declared here
  void __sanitizer_finish_switch_fiber(void *fake_stack_save,
  ^
/home/ubuntu/tarantool/src/fiber.c:626:2: error: too few arguments to function call, expected 3, have 1
        ASAN_FINISH_SWITCH_FIBER(NULL);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ubuntu/tarantool/src/fiber.c:57:42: note: expanded from macro 'ASAN_FINISH_SWITCH_FIBER'
        __sanitizer_finish_switch_fiber(var_name);
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         ^
/usr/local/lib/clang/5.0.0/include/sanitizer/common_interface_defs.h:184:3: note: '__sanitizer_finish_switch_fiber' declared here
  void __sanitizer_finish_switch_fiber(void *fake_stack_save,
  ^
3 errors generated.
src/CMakeFiles/core.dir/build.make:158: recipe for target 'src/CMakeFiles/core.dir/fiber.c.o' failed
make[2]: *** [src/CMakeFiles/core.dir/fiber.c.o] Error 1
CMakeFiles/Makefile2:584: recipe for target 'src/CMakeFiles/core.dir/all' failed
make[1]: *** [src/CMakeFiles/core.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
@kostja kostja added this to the wishlist milestone Feb 7, 2018
@kostja kostja added the qa Issues related to tests or testing subsystem label Feb 13, 2018
Totktonada added a commit that referenced this issue Dec 20, 2018
Totktonada added a commit that referenced this issue Dec 20, 2018
It still supports only clang, so use CC=clang CXX=clang++ cmake
-DENABLE_ASAN on systems where gcc is default compiler.

Fixes #3070.
Totktonada added a commit that referenced this issue Dec 20, 2018
LLVM changes the API in the compiler-rt commit [1]. According to the
date of the commit it is between clang-3.9.0 and clang-3.9.1.

[1]: llvm-mirror/compiler-rt@0b95585

Fixes #3070.
kyukhin pushed a commit that referenced this issue Dec 21, 2018
LLVM changes the API in the compiler-rt commit [1]. According to the
date of the commit it is between clang-3.9.0 and clang-3.9.1.

[1]: llvm-mirror/compiler-rt@0b95585

Fixes #3070.
@evverx
Copy link
Author

evverx commented Dec 21, 2018

Thank you! To judge from CMakeError.log the build system can tell the interfaces apart. tarantool itself seems to be failing to compile with:

In file included from lj_obj.h:13,
                 from lj_str.c:9:
lj_str.c: In function ‘str_fastcmp’:
lj_def.h:242:28: error: inlining failed in call to always_inline ‘lj_getu32’: function attribute mismatch
 static LJ_AINLINE uint32_t lj_getu32(const void *p)
                            ^~~~~~~~~
lj_str.c:59:18: note: called from here
     uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i);
                  ^~~~~~~~~~~~~~
lj_str.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
make[3]: *** [Makefile:683: lj_str.o] Error 1
make[2]: *** [CMakeFiles/libluajit.dir/build.make:62: third_party/luajit/src/libluajit.a] Error 2
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/libluajit.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 19%] Building C object src/lib/small/test/CMakeFiles/quota.test.dir/unit.c.o
[ 19%] Linking C executable lsregion.test
[ 19%] Linking CXX executable quota.test
[ 19%] Built target quota_lessor.test
[ 19%] Built target lsregion.test
[ 19%] Built target quota.test
make: *** [Makefile:152: all] Error 2

@evverx
Copy link
Author

evverx commented Dec 21, 2018

That was gcc (GCC) 8.2.1 20181105 (Red Hat 8.2.1-5) on Fedora 28. When built with clang-6.0.1 it is failing with:

Scanning dependencies of target ratelimit.test
[ 33%] Building C object test/unit/CMakeFiles/ratelimit.test.dir/ratelimit.c.o

=================================================================
==18875==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x4e1240 in calloc (/home/vagrant/tarantool/extra/lemon+0x4e1240)
    #1 0x5154ca in acttab_alloc /home/vagrant/tarantool/extra/lemon.c:608:26
    #2 0x52f87f in ReportTable /home/vagrant/tarantool/extra/lemon.c:4143:13
    #3 0x524cf6 in main /home/vagrant/tarantool/extra/lemon.c:1717:5
    #4 0x7f37efe4411a in __libc_start_main (/lib64/libc.so.6+0x2311a)

Indirect leak of 20896 byte(s) in 1 object(s) allocated from:
    #0 0x4e14a0 in realloc (/home/vagrant/tarantool/extra/lemon+0x4e14a0)
    #1 0x516220 in acttab_insert /home/vagrant/tarantool/extra/lemon.c:667:46
    #2 0x53038a in ReportTable /home/vagrant/tarantool/extra/lemon.c:4166:22
    #3 0x524cf6 in main /home/vagrant/tarantool/extra/lemon.c:1717:5
    #4 0x7f37efe4411a in __libc_start_main (/lib64/libc.so.6+0x2311a)

Indirect leak of 400 byte(s) in 1 object(s) allocated from:
    #0 0x4e14a0 in realloc (/home/vagrant/tarantool/extra/lemon+0x4e14a0)
    #1 0x515704 in acttab_action /home/vagrant/tarantool/extra/lemon.c:625:49
    #2 0x52fcc8 in ReportTable /home/vagrant/tarantool/extra/lemon.c:4152:9
    #3 0x524cf6 in main /home/vagrant/tarantool/extra/lemon.c:1717:5
    #4 0x7f37efe4411a in __libc_start_main (/lib64/libc.so.6+0x2311a)

SUMMARY: AddressSanitizer: 21344 byte(s) leaked in 3 allocation(s).

@Totktonada
Copy link
Member

  1. We support only clang's ASAN: https://github.com/tarantool/tarantool/wiki/Address-Sanitizer

Use git clean -xfd; git submodule foreach --recursive git clean -xfd before CC=clang CXX=clang++ cmake . <...> -DENABLE_ASAN=ON && make -j.

  1. Sure, there are some reports from ASAN. Don't sure whether they are false positives or real. We'll investigate them in the scope of gitlab CI: add ASAN builds  #2058.

@evverx
Copy link
Author

evverx commented Dec 21, 2018

We support only clang's ASAN: https://github.com/tarantool/tarantool/wiki/Address-Sanitizer

it'd probably be great to build this knowledge into the build system.

We'll investigate them in the scope of #2058.

That's good to know but technically tarantool still fails to compile when ENABLE_ASAN=on so I'd reopen the issue if I could :-)

@Totktonada
Copy link
Member

We support only clang's ASAN: https://github.com/tarantool/tarantool/wiki/Address-Sanitizer
it'd probably be great to build this knowledge into the build system.

Ok, I'll create follow up patch.

@evverx
Copy link
Author

evverx commented Dec 21, 2018

I've just taken a look at #2058 and as far as I can see it covers ASan only. I think it'd be also great to try UBSan (though it apparently isn't as easy as it seems to be). I built tarantool with it and the tests crashed somewhere in luajit

[007] lj_obj.h:874:3: runtime error: member access within misaligned address 0x000041619444 for type 'union GCobj', which requires 8 byte alignment
[007] 0x000041619444: note: pointer points here
[007]   00 00 00 00 00 00 00 00  01 04 00 00 00 00 00 00  00 00 00 00 00 00 00 00  78 93 61 41 00 00 00 00
[007]               ^
[007]     #0 0x766017 in setgcVraw /home/vagrant/tarantool/third_party/luajit/src/lj_obj.h:874
[007]     #1 0x766017 in setgcV /home/vagrant/tarantool/third_party/luajit/src/lj_obj.h:880
[007]     #2 0x766017 in setstrV /home/vagrant/tarantool/third_party/luajit/src/lj_obj.h:888
[007]     #3 0x766017 in lua_pushstring /home/vagrant/tarantool/third_party/luajit/src/lj_api.c:663
[007]     #4 0x9913fe in luaL_openlibs /home/vagrant/tarantool/third_party/luajit/src/lib_init.c:44
[007]     #5 0x661a16 in tarantool_lua_init /home/vagrant/tarantool/src/lua/init.c:434
[007]     #6 0x41786f in main /home/vagrant/tarantool/src/main.cc:747
[007]     #7 0x7fa69c08711a in __libc_start_main (/lib64/libc.so.6+0x2311a)
[007]     #8 0x415af9 in _start (/home/vagrant/tarantool/src/tarantool+0x415af9)
[007]
[007] SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lj_obj.h:874:3 in
[Main process] Got failed test; gently terminate all workers...

@evverx
Copy link
Author

evverx commented Dec 21, 2018

Anyway, it's time for me to stop here. Thanks again for fixing this!

Totktonada added a commit that referenced this issue Dec 23, 2018
The build time error is confusing for users. The patch makes the error
explicit and moves it to the cmake stage.

Follow up of #3070.
locker pushed a commit that referenced this issue Dec 24, 2018
The build time error is confusing for users. The patch makes the error
explicit and moves it to the cmake stage.

Follow up of #3070.
locker pushed a commit that referenced this issue Dec 24, 2018
The build time error is confusing for users. The patch makes the error
explicit and moves it to the cmake stage.

Follow up of #3070.

(cherry picked from commit d79a1bc)
gdrbyKo1 pushed a commit to gdrbyKo1/tarantool that referenced this issue Jan 17, 2019
LLVM changes the API in the compiler-rt commit [1]. According to the
date of the commit it is between clang-3.9.0 and clang-3.9.1.

[1]: llvm-mirror/compiler-rt@0b95585

Fixes tarantool#3070.
gdrbyKo1 pushed a commit to gdrbyKo1/tarantool that referenced this issue Jan 17, 2019
The build time error is confusing for users. The patch makes the error
explicit and moves it to the cmake stage.

Follow up of tarantool#3070.
@kostja kostja removed this from the wishlist milestone Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qa Issues related to tests or testing subsystem
Projects
None yet
Development

No branches or pull requests

3 participants