viralcode / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
1 stars 0 forks source link

can't static link against gflags #30

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. link the main program against libgflags.so
2. the program runs normally.
3. link the main program against libgflags.a
4. the program crashes and cores dump before main.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
latest llvm 3.1

Please provide any additional information below.
Is there any trick in gflags that makes it incompatible to asan when static 
linked?

Original issue reported on code.google.com by huas...@gmail.com on 23 Jan 2012 at 7:16

GoogleCodeExporter commented 9 years ago
Could you please run this under gdb and provide the crash stack trace? 

Original comment by konstant...@gmail.com on 23 Jan 2012 at 7:21

GoogleCodeExporter commented 9 years ago
btw, I was not able to reproduce this with gflags-1.7 on 64-bit Ubuntu Linux. 
Please provide more detailed info (gdb stack traces and detailed reproducer 
steps)

Original comment by konstant...@gmail.com on 23 Jan 2012 at 7:55

GoogleCodeExporter commented 9 years ago
I uses gflags-1.7 on 64-bit CentOS 6.1 (with kernel 2.6.32, same to Ubuntu 
10.04)

the testing program tarball is attached, just run make in the decompressed 
directory to see what happens.

Original comment by huas...@gmail.com on 23 Jan 2012 at 8:12

Attachments:

GoogleCodeExporter commented 9 years ago
Typing 'make all' leads to this: 

clang++ main.cc -I./ -L./so -lgflags -Wl,-rpath,./so -faddress-sanitizer 
-fno-omit-frame-pointer -o dynamic.out
./dynamic.out
hello world!
clang++ main.cc -I./ -L./a -lgflags -faddress-sanitizer -fno-omit-frame-pointer 
-o static.out
./static.out
hello world!

I guess something special in the libc of CentOS 6.1 makes asan fail. 
Need gdb stack trace.... 

Original comment by konstant...@gmail.com on 23 Jan 2012 at 8:17

GoogleCodeExporter commented 9 years ago
sorry forgot to post gdb outputs:

$ gdb ./static.out 
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from 
/home/suhua/codebase/wly.clang/test/asan_with_gflgs/static.out...done.
(gdb) r
Starting program: 
/home/suhua/codebase/wly.clang/test/asan_with_gflgs/static.out 
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x000000000041a40b in __asan_address_is_poisoned ()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6.x86_64 
libgcc-4.4.6-3.el6.x86_64 libstdc++-4.4.6-3.el6.x86_64
(gdb) bt
#0  0x000000000041a40b in __asan_address_is_poisoned ()
#1  0x0000000000417ee6 in __asan::AccessAddress(unsigned long, bool) ()
#2  0x00000000004184d7 in strcmp ()
#3  0x0000003a522be7fe in __cxxabiv1::__vmi_class_type_info::__do_dyncast(long, 
__cxxabiv1::__class_type_info::__sub_kind, __cxxabiv1::__class_type_info 
const*, void const*, __cxxabiv1::__class_type_info const*, void const*, 
__cxxabiv1::__class_type_info::__dyncast_result&) const () from 
/usr/lib64/libstdc++.so.6
#4  0x0000003a522bb3ed in __dynamic_cast () from /usr/lib64/libstdc++.so.6
#5  0x0000003a5227dd2b in bool std::has_facet<std::ctype<char> >(std::locale 
const&) () from /usr/lib64/libstdc++.so.6
#6  0x0000003a522742a4 in std::basic_ios<char, std::char_traits<char> 
>::_M_cache_locale(std::locale const&) ()
   from /usr/lib64/libstdc++.so.6
#7  0x0000003a52274348 in std::basic_ios<char, std::char_traits<char> 
>::init(std::basic_streambuf<char, std::char_traits<char> >*) ()
   from /usr/lib64/libstdc++.so.6
#8  0x0000003a52262de1 in std::ios_base::Init::Init() () from 
/usr/lib64/libstdc++.so.6
#9  0x000000000041314e in __static_initialization_and_destruction_0 ()
    at /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/iostream:72
#10 global constructors keyed to _ZN3fLS25FLAGS_tab_completion_wordE() () at 
src/gflags_completions.cc:768
#11 0x0000000000420aa6 in __do_global_ctors_aux ()
#12 0x0000000000407fb3 in _init ()
#13 0x00007fffffffd128 in ?? ()
#14 0x0000000000420a15 in __libc_csu_init ()
#15 0x0000003a45e1ec70 in __libc_start_main () from /lib64/libc.so.6
#16 0x00000000004085f9 in _start ()

Original comment by huas...@gmail.com on 23 Jan 2012 at 8:26

GoogleCodeExporter commented 9 years ago
Yea, initialization problem... 
gflags, which is not built with asan, does it's global CTORs before any 
instrumented code does. The gflags' CTORs call strcmp, which accesses shadow 
memory, but __asan_init has not yet been called. 

We must make sure that __asan_init is called before everything else. 
One option is to build gflags with asan. 
Another option, call __asan_init from preinit array. 

Could you please make an experiment? 
What will happen if you add the following somewhere in your code?

extern "C" void __asan_init();
__attribute__((section(".preinit_array")))
  typeof(__asan_init) *__asan_preinit =__asan_init;

Original comment by konstant...@gmail.com on 23 Jan 2012 at 8:33

GoogleCodeExporter commented 9 years ago
I put __asan_init lines in main.cc, and no luck:

clang++ main.cc -I./ -L./so -lgflags -Wl,-rpath,./so -faddress-sanitizer 
-fno-omit-frame-pointer -o dynamic.out
./dynamic.out
ASAN:SIGSEGV
==3525== ERROR: AddressSanitizer crashed on unknown address 0x000000000000 (pc 
0x000000000000 sp 0x7fff46cc6a88 bp 0x7fff46cc6af8 T0)
AddressSanitizer can not provide additional info. ABORTING
Stats: 0M malloced (0M for red zones) by 0 calls
Stats: 0M realloced by 0 calls
Stats: 0M freed by 0 calls
Stats: 0M really freed by 0 calls
Stats: 0M (0 full pages) mmaped in 0 calls
  mmaps   by size class: 
  mallocs by size class: 
  frees   by size class: 
  rfrees  by size class: 
Stats: malloc large: 0 small slow: 0

Original comment by huas...@gmail.com on 23 Jan 2012 at 8:38

GoogleCodeExporter commented 9 years ago
and the static linked version:

clang++ main.cc -I./ -L./a -lgflags -faddress-sanitizer -fno-omit-frame-pointer 
-o static.out
./static.out
ASAN:SIGSEGV
==3538== ERROR: AddressSanitizer crashed on unknown address 0x000000000000 (pc 
0x000000000000 sp 0x7fffc0a03948 bp 0x7fffc0a039b8 T0)
AddressSanitizer can not provide additional info. ABORTING
Stats: 0M malloced (0M for red zones) by 0 calls
Stats: 0M realloced by 0 calls
Stats: 0M freed by 0 calls
Stats: 0M really freed by 0 calls
Stats: 0M (0 full pages) mmaped in 0 calls
  mmaps   by size class: 
  mallocs by size class: 
  frees   by size class: 
  rfrees  by size class: 
Stats: malloc large: 0 small slow: 0

Original comment by huas...@gmail.com on 23 Jan 2012 at 8:39

GoogleCodeExporter commented 9 years ago
gdb stack trace? 

Original comment by konstant...@gmail.com on 23 Jan 2012 at 9:10

GoogleCodeExporter commented 9 years ago
$ gdb ./dynamic.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from 
/home/suhua/codebase/wly.clang/test/asan_with_gflgs/dynamic.out...done.
(gdb) r
Starting program: 
/home/suhua/codebase/wly.clang/test/asan_with_gflgs/dynamic.out 
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6.x86_64 
libgcc-4.4.6-3.el6.x86_64 libstdc++-4.4.6-3.el6.x86_64
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x0000003a4560e552 in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2
#2  0x0000003a45600b3a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#3  0x0000000000000001 in ?? ()
#4  0x00007fffffffd41b in ?? ()
#5  0x0000000000000000 in ?? ()

Original comment by huas...@gmail.com on 23 Jan 2012 at 9:23

GoogleCodeExporter commented 9 years ago
$ gdb ./static.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from 
/home/suhua/codebase/wly.clang/test/asan_with_gflgs/static.out...done.
(gdb) r

Starting program: 
/home/suhua/codebase/wly.clang/test/asan_with_gflgs/static.out 
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6.x86_64 
libgcc-4.4.6-3.el6.x86_64 libstdc++-4.4.6-3.el6.x86_64
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x0000003a4560e552 in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2
#2  0x0000003a45600b3a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#3  0x0000000000000001 in ?? ()
#4  0x00007fffffffd41d in ?? ()
#5  0x0000000000000000 in ?? ()

Original comment by huas...@gmail.com on 23 Jan 2012 at 9:25

GoogleCodeExporter commented 9 years ago
Please also try llvm r148726.
I changed the strcmp wrapper, so, if you still have the failure it will likely 
be somewhere else

Original comment by konstant...@gmail.com on 23 Jan 2012 at 9:25

GoogleCodeExporter commented 9 years ago
I can not reproduce it and there is a chance that r148726 fixed this. 
Please reopen if you still see this. 

Original comment by konstant...@gmail.com on 31 Jan 2012 at 12:27