{"action":"created","issue":{"url":"https://api.github.com/repos/gnustep/libobjc2/issues/19","repository_url":"https://api.github.com/repos/gnustep/libobjc2","labels_url":"https://api.github.com/repos/gnustep/libobjc2/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/gnustep/libobjc2/issues/19/comments","events_url":"https://api.github.com/repos/gnustep/libobjc2/issues/19/events","html_url":"https://github.com/gnustep/libobjc2/issues/19","id":176474913,"number":19,"title":"Result of ivar_getTypeEncoding only contains one character for object-valued ivars under clang on Linux","user":{"login":"dlobron","id":16092520,"avatar_url":"https://avatars.githubusercontent.com/u/16092520?v=3","gravatar_id":"","url":"https://api.github.com/users/dlobron","html_url":"https://github.com/dlobron","followers_url":"https://api.github.com/users/dlobron/followers","following_url":"https://api.github.com/users/dlobron/following{/other_user}","gists_url":"https://api.github.com/users/dlobron/gists{/gist_id}","starred_url":"https://api.github.com/users/dlobron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlobron/subscriptions","organizations_url":"https://api.github.com/users/dlobron/orgs","repos_url":"https://api.github.com/users/dlobron/repos","events_url":"https://api.github.com/users/dlobron/events{/privacy}","received_events_url":"https://api.github.com/users/dlobron/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-12T20:24:18Z","updated_at":"2016-09-14T19:33:39Z","closed_at":null,"body":"I recently compiled an Objective-C program on Linux using clang/llvm .  I'm using libobjc2-1.8.1, with llvm 3.7.  My program links with a shared library (also written in ObjC), which introspects the instance variables in a common Configuration class to determine what type each of those variables is.  This has always worked on the Mac with clang and on Linux with gcc.  However, with clang/llvm on Linux, I'm finding that the type introspection fails.  The shared library code looks like this:\r\n\r\n```\r\nIvar *ivarList = class_copyIvarList(c, &ivarCount);\r\nfor (i = 0; i < ivarCount; i++) {\r\n   Ivar ivar = ivarList[i];\r\n   const char *ivarCname = ivar_getName(ivar);\r\n   if (ivarCname != 0 && ivarCname[0] != '_') {\r\n        NSString *ivarName = [NSString stringWithUTF8String:ivarCname];\r\n        const char *ivarType = ivar_getTypeEncoding(ivar);\r\n        bool isObjectValuedIvar = (ivarType[0] == '@' && ivarType[1] == '\"')\r\n        if (isObjectValuedIvar) {\r\n            NSString *className = [[[NSString alloc] initWithBytes: &ivarType[2]\r\n                                            length: strlen(&ivarType[2])-1\r\n                                        encoding: NSUTF8StringEncoding] autorelease];\r\n           Class c = NSClassFromString(className);\r\n```\r\n\r\nI'm finding that the call to ivar_getTypeEncoding returns \"@\" in the ivarType variable.  However, that variable only contains \"@\".  It doesn't have any element 1 or 2, and my code seg faults when I try to access them.  I ran the code under gdb with optimization turned off, and verified that the ivarCname and ivarType variables contain the variable name and \"@\", respectively:\r\n\r\n(gdb) print ivarCname\r\n$9 = 0x4a4575 \"sslCertificateFile\"\r\n(gdb) print ivarType\r\n$5 = 0x4a5951 \"@\"\r\n\r\nShould the call to ivar_getTypeEncoding be returning more than \"@\"? \r\n\r\nAnother oddity here is that the ivar object itself seems opaque.  I can't seem to print the struct members:\r\n\r\n(gdb) print ivar\r\n$12 = (Ivar) 0x6e1160 <.objc_ivar_list+776>\r\n(gdb) print ivar.name\r\nThere is no member named name.\r\n(gdb) print ivar.type\r\nThere is no member named type.\r\n(gdb) print ivar->type\r\nThere is no member named type.\r\n\r\nI'm not sure how this is possible, because the ivar_getTypeEncoding function just does this:\r\n\r\n```\r\nconst char * ivar_getTypeEncoding(Ivar ivar)\r\n{\r\n        CHECK_ARG(ivar);\r\n        return ivar->type;\r\n}\r\n```\r\n\r\nI'd appreciate any help here!  I'm wondering if my code is somehow finding different versions of the runtime - I'm not sure how I can determine that beyond using gdb."},"comment":{"url":"https://api.github.com/repos/gnustep/libobjc2/issues/comments/247128283","html_url":"https://github.com/gnustep/libobjc2/issues/19#issuecomment-247128283","issue_url":"https://api.github.com/repos/gnustep/libobjc2/issues/19","id":247128283,"user":{"login":"dlobron","id":16092520,"avatar_url":"https://avatars.githubusercontent.com/u/16092520?v=3","gravatar_id":"","url":"https://api.github.com/users/dlobron","html_url":"https://github.com/dlobron","followers_url":"https://api.github.com/users/dlobron/followers","following_url":"https://api.github.com/users/dlobron/following{/other_user}","gists_url":"https://api.github.com/users/dlobron/gists{/gist_id}","starred_url":"https://api.github.com/users/dlobron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlobron/subscriptions","organizations_url":"https://api.github.com/users/dlobron/orgs","repos_url":"https://api.github.com/users/dlobron/repos","events_url":"https://api.github.com/users/dlobron/events{/privacy}","received_events_url":"https://api.github.com/users/dlobron/received_events","type":"User","site_admin":false},"created_at":"2016-09-14T19:33:39Z","updated_at":"2016-09-14T19:33:39Z","body":"Hey David, I rebuilt my tree with gcc, and confirmed that the problem goes away there.  So it seems like clang is not providing this info.\r\n\r\nI looked at `lib/CodeGen/CGObjCGNU.cpp`, but I could not immediately tell what the proper option would be to tell clang to emit the class info.  Would you like me to raise this on the clang email list?  I'm kind of surprised by this bug, because my library's introspection code runs correctly on my Mac, where I'm compiling with clang.  Apple's version may have diverged from the public one in this case."}}
{"actor":{"display_login":"dlobron"}}