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

Segmentation fault occurs with tcmalloc #18

Closed
dlobron opened this issue Jun 20, 2016 · 4 comments
Closed

Segmentation fault occurs with tcmalloc #18

dlobron opened this issue Jun 20, 2016 · 4 comments

Comments

@dlobron
Copy link

dlobron commented Jun 20, 2016

I have a program that I'd like to run under gnustep on an Ubuntu Linux system, linking with libobjc.so.4.6, building with clang/llvm. The program builds without any obvious problems. However, when I try to run it, I get an immediate segmentation fault, even before the start of my main() method. The stack trace, which I've copied below, suggests a problem with startup memory allocation. I'm compiling with tcmalloc-gperftools-r218.

Please let me know if there's anything I might do to debug this, or if it's more likely a bug on my side.
#0 tcmalloc::ThreadCache::Init (this=0x81b098, tid=)

at src/thread_cache.cc:116

#1 0x0000000000481187 in tcmalloc::ThreadCache::NewHeap (tid=140737353975744) at src/thread_cache.cc:398
#2 0x000000000048100b in tcmalloc::ThreadCache::CreateCacheIfNecessary () at src/thread_cache.cc:375
#3 0x00000000004766ab in GetCache () at ./src/thread_cache.h:423
#4 (anonymous namespace)::do_malloc_no_errno (size=24) at src/tcmalloc.cc:1236
#5 0x00000000004ad1f2 in do_malloc_no_errno_or_cpp_alloc (size=24) at src/tcmalloc.cc:1167
#6 do_calloc (n=, elem_size=) at src/tcmalloc.cc:1253
#7 tc_calloc (n=, elem_size=) at src/tcmalloc.cc:1749
#8 0x00007ffff5e70251 in SparseArrayNewWithDepth () from /home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#9 0x00007ffff5e7035e in SparseArrayNew () from /home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#10 0x00007ffff5e70e3b in init_selector_tables () from /home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#11 0x00007ffff5e6b916 in __objc_exec_class () from /home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#12 0x00007ffff5e7511f in .objc_load_function () from /home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#13 0x00007ffff7dea13a in call_init (l=, argc=argc@entry=3, argv=argv@entry=0x7fffffffe198, env=env@entry=0x7fffffffe1b8) at dl-init.c:78
#14 0x00007ffff7dea223 in call_init (env=, argv=, argc=, l=) at dl-init.c:36
#15 _dl_init (main_map=0x7ffff7ffe1c8, argc=3, argv=0x7fffffffe198, env=0x7fffffffe1b8) at dl-init.c:126
#16 0x00007ffff7ddb30a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2

@davidchisnall
Copy link
Member

There isn't really enough information here for me to be able to diagnose what's happening. The code that is responsible for initialising the runtime is allocating memory and this is causing tcmalloc to die. It would help if you could compile a debug build of libobjc2, but it looks from frame 4 as if the allocation size is 24 bytes, which shouldn't be failing.

Does tcmalloc rely on global constructors for any of its state? If so, then you may be hitting problems caused by execution order, with the ones in libobjc2 firing first.

@ngrewe
Copy link
Member

ngrewe commented Jun 21, 2016

fwiw, I routinely work with a system that uses libobjc2 (master-ish snapshot) in conjunction with tcmalloc from gperftools-2.4, and haven't seen this issue yet.

@dlobron
Copy link
Author

dlobron commented Jun 21, 2016

Thank you for the help, guys. I did a debug build of libobjc2, and I got a little more data in the stack trace- I've copied it below. I'm going to also try a build without tcmalloc.

Stack trace with a debug build of libobjc2:

#0  tcmalloc::ThreadCache::Init (this=0x81b098, tid=<error reading variable: access outside bounds of object referenced via synthetic pointer>)
    at src/thread_cache.cc:116
#1  0x0000000000481187 in tcmalloc::ThreadCache::NewHeap (tid=140737353975744) at src/thread_cache.cc:398
#2  0x000000000048100b in tcmalloc::ThreadCache::CreateCacheIfNecessary () at src/thread_cache.cc:375
#3  0x00000000004766ab in GetCache () at ./src/thread_cache.h:423
#4  (anonymous namespace)::do_malloc_no_errno (size=24) at src/tcmalloc.cc:1236
#5  0x00000000004ad1f2 in do_malloc_no_errno_or_cpp_alloc (size=24) at src/tcmalloc.cc:1167
#6  do_calloc (n=<optimized out>, elem_size=<optimized out>) at src/tcmalloc.cc:1253
#7  tc_calloc (n=<optimized out>, elem_size=<optimized out>) at src/tcmalloc.cc:1749
#8  0x00007ffff5e70251 in SparseArrayNewWithDepth (depth=32) at /home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/sarray2.c:57
#9  0x00007ffff5e7035e in SparseArrayNew () at /home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/sarray2.c:67
#10 0x00007ffff5e70e3b in init_selector_tables () at /home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/selector_table.c:260
#11 0x00007ffff5e6b916 in __objc_exec_class (module=0x7ffff6085668 <__unnamed_1>) at /home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/loader.c:72
#12 0x00007ffff5e7511f in .objc_load_function () from /home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#13 0x00007ffff7dea13a in call_init (l=<optimized out>, argc=argc@entry=3, argv=argv@entry=0x7fffffffe1c8, env=env@entry=0x7fffffffe1e8) at dl-init.c:78
#14 0x00007ffff7dea223 in call_init (env=<optimized out>, argv=<optimized out>, argc=<optimized out>, l=<optimized out>) at dl-init.c:36
#15 _dl_init (main_map=0x7ffff7ffe1c8, argc=3, argv=0x7fffffffe1c8, env=0x7fffffffe1e8) at dl-init.c:126
#16 0x00007ffff7ddb30a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#17 0x0000000000000003 in ?? ()
#18 0x00007fffffffe4b5 in ?? ()
#19 0x00007fffffffe4fa in ?? ()
#20 0x00007fffffffe4fd in ?? ()
#21 0x0000000000000000 in ?? ()

@davidchisnall
Copy link
Member

This looks like something has corrupted tcmalloc's internal data structures, or it has not managed to set things up before the constructors run.

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

No branches or pull requests

3 participants