[cfe-users] Segmentation fault on startup from Objective-C program

2016-05-12 Thread Lobron, David via cfe-users
Hello clang experts,

I am working to get an existing codeline built and running with LLVM clang, 
version 3.7.  My current target program is written in Objective-C, and I'm 
using libobjc2 version 1.8.1 (the shared library it produces is 
libobjc.so.4.6).  I'm also using tcmalloc, version gperftools-r218.  This is on 
an Ubuntu Linux system, 3.2.0-98-generic.

I'm finding that my ObjC program crashes on startup.  The stack trace (copied 
below) terminates in some tcmalloc functions, and seems to be due to an attempt 
to reference memory outside allowed bounds.  I'm not sure where to start 
debugging this.  I would welcome any help from more knowledgeable people on 
this list.

Thank you,

David

Stack trace from gdb:

Program received signal SIGSEGV, Segmentation fault.
tcmalloc::ThreadCache::Init (this=0x81b098, tid=) at 
src/thread_cache.cc:116
116   max_size_ = 0;
(gdb) bt
#0  tcmalloc::ThreadCache::Init (this=0x81b098, tid=)
at src/thread_cache.cc:116
#1  0x00481187 in tcmalloc::ThreadCache::NewHeap (tid=140737353979840) 
at src/thread_cache.cc:398
#2  0x0048100b in tcmalloc::ThreadCache::CreateCacheIfNecessary () at 
src/thread_cache.cc:375
#3  0x004766ab in GetCache () at ./src/thread_cache.h:423
#4  (anonymous namespace)::do_malloc_no_errno (size=24) at src/tcmalloc.cc:1236
#5  0x004ad1f2 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  0x75e70251 in SparseArrayNewWithDepth () from 
/home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#9  0x75e7035e in SparseArrayNew () from 
/home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#10 0x75e70e3b in init_selector_tables () from 
/home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#11 0x75e6b916 in __objc_exec_class () from 
/home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#12 0x75e7511f in .objc_load_function () from 
/home/dlobron/build/clangport/akamai/common/lib/libobjc.so.4.6
#13 0x77dea13a in call_init (l=, argc=argc@entry=3, 
argv=argv@entry=0x7fffe1c8, env=env@entry=0x7fffe1e8) at dl-init.c:78
#14 0x77dea223 in call_init (env=, argv=, 
argc=, l=) at dl-init.c:36
#15 _dl_init (main_map=0x77ffe1c8, argc=3, argv=0x7fffe1c8, 
env=0x7fffe1e8) at dl-init.c:126
#16 0x77ddb30a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#17 0x0003 in ?? ()
#18 0x7fffe4b5 in ?? ()
#19 0x7fffe4fa in ?? ()
#20 0x7fffe4fd in ?? ()
#21 0x in ?? ()
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] clang does not emit Ivar class name when compiling libobjc2 on Linux (Mac and gcc Linux are OK)

2016-09-15 Thread Lobron, David via cfe-users
Hello cfe-users,

I'm working to get my the libobjc2 Objective-C runtime working on Linux with 
clang-3.8.0.  I'm running into a problem with a library of mine that does class 
introspection.  My ObjC code does type introspection by looping through the 
ivars of an object and calling ivar_getTypeEncoding on each to get the type of 
the ivar.  When I compile with gcc, the ivar type for non-primitive variables 
comes through as @"NSString", @"NSDictionary", etc.  This also works with clang 
on my Mac.  But when I compile with clang on Linux, I only get the @ character. 
 I verified that the call to class_copyIvarList on Linux does return a list of 
Ivar objects, but when I call ivar_getTypeEncoding on those objects on Linux, I 
only get @, rather than the class name.  I've copied my library's ObjC code 
below.  

I talked this over with the owners of libobjc2, and we were wondering if there 
is a flag I can pass to clang to instruct it to emit this class data.  I looked 
at lib/CodeGen/CGObjCGNU.cpp in the clang source tree, but it wasn't 
immediately clear what flag I could pass here.  It's possible that there's no 
such flag, and the non-Apple clang simply doesn't emit this data, but I'd be 
somewhat surprised if Apple had diverged that much.

Thanks in advance for any help you can give,

David

My library's introspection code, with a debug print statement:

Ivar *ivarList = class_copyIvarList(c, &ivarCount);
for (i = 0; i < ivarCount; i++) {
  Ivar ivar = ivarList[i];
  const char *ivarCname = ivar_getName(ivar);
  if (ivarCname != 0 && ivarCname[0] != '_') {
 NSString *ivarName = [NSString stringWithUTF8String:ivarCname];
 const char *ivarType = ivar_getTypeEncoding(ivar);
 if (ivarType[0] == '@' && ivarType[1] == '"') {
 NSString *className = [[[NSString alloc] initWithBytes: &ivarType[2]
  length: strlen(&ivarType[2])-1
 encoding: NSUTF8StringEncoding] autorelease];
 Class c = NSClassFromString(className);
 if (c == nil) {
 NSLog(@"WARNING: unknown class name \"%@\" in declaration of %@", 
className, [self class]);
 } else {
 NSLog(@"DBG: Deduced class %@ from className %@", c, className);

With gcc and clang on the Mac, I get messages like this:

2016-09-14 19:29:21.950 archiveserver[1015:1015] DBG: Deduced class NSSet from 
className NSSet
2016-09-14 19:29:21.950 archiveserver[1015:1015] DBG: Deduced class NSString 
from className NSString
2016-09-14 19:29:21.950 archiveserver[1015:1015] DBG: Deduced class NSString 
from className NSString
2016-09-14 19:29:21.950 archiveserver[1015:1015] DBG: Deduced class NSString 
from className NSString
2016-09-14 19:29:21.950 archiveserver[1015:1015] DBG: Deduced class 
NSDictionary from className NSDictionary
2016-09-14 19:29:21.950 archiveserver[1015:1015] DBG: Deduced class 
NSDictionary from className NSDictionary
2016-09-14 19:29:21.950 archiveserver[1015:1015] DBG: Deduced class NSArray 
from className NSArray

With clang on Linux, nothing is printed, because ivarType[1] is not a double 
quote, so the second if evaluates to false.



___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users