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

can't static link against gflags #30

Closed
ramosian-glider opened this issue Aug 31, 2015 · 14 comments
Closed

can't static link against gflags #30

ramosian-glider opened this issue Aug 31, 2015 · 14 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 30

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?

Reported by huas.su on 2012-01-23 19:16:58

@ramosian-glider
Copy link
Member Author

Could you please run this under gdb and provide the crash stack trace? 

Reported by konstantin.s.serebryany on 2012-01-23 19:21:10

@ramosian-glider
Copy link
Member Author

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)

Reported by konstantin.s.serebryany on 2012-01-23 19:55:24

  • Status changed: Invalid

@ramosian-glider
Copy link
Member Author

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.

Reported by huas.su on 2012-01-23 20:12:06


- _Attachment: [asan_with_gflgs.tar.gz](https://storage.googleapis.com/google-code-attachments/address-sanitizer/issue-30/comment-3/asan_with_gflgs.tar.gz)_

@ramosian-glider
Copy link
Member Author

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.... 

Reported by konstantin.s.serebryany on 2012-01-23 20:17:18

@ramosian-glider
Copy link
Member Author

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 ()

Reported by huas.su on 2012-01-23 20:26:48

@ramosian-glider
Copy link
Member Author

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;



Reported by konstantin.s.serebryany on 2012-01-23 20:33:26

  • Status changed: Accepted

@ramosian-glider
Copy link
Member Author

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

Reported by huas.su on 2012-01-23 20:38:04

@ramosian-glider
Copy link
Member Author

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

Reported by huas.su on 2012-01-23 20:39:08

@ramosian-glider
Copy link
Member Author

gdb stack trace? 

Reported by konstantin.s.serebryany on 2012-01-23 21:10:28

@ramosian-glider
Copy link
Member Author

$ 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 ?? ()

Reported by huas.su on 2012-01-23 21:23:49

@ramosian-glider
Copy link
Member Author

$ 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 ?? ()

Reported by huas.su on 2012-01-23 21:25:13

@ramosian-glider
Copy link
Member Author

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

Reported by konstantin.s.serebryany on 2012-01-23 21:25:13

@ramosian-glider
Copy link
Member Author

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

Reported by konstantin.s.serebryany on 2012-01-31 00:27:30

  • Status changed: Fixed

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:12:58

  • Labels added: ProjectAddressSanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant