struct _objc_method {
SEL _cmd;
char *method_types;
void *_imp;
};
static struct {
struct _objc_method_list *next_method;
int method_count;
struct _objc_method method_list[1];
} _OBJC_CLASS_METHODS_X __attribute__ ((used, section ("__OBJC, __cls_meth")))
=
{
0, 1
,{{(SEL)"print", "v8@0:4", (void *)_C_X_print}
}
};
struct _objc_class {
struct _objc_class *isa;
const char *super_class_name;
char *name;
long version;
long info;
long instance_size;
struct _objc_ivar_list *ivars;
struct _objc_method_list *methods;
struct objc_cache *cache;
struct _objc_protocol_list *protocols;
const char *ivar_layout;
struct _objc_class_ext *ext;
};static struct _objc_class _OBJC_METACLASS_X __attribute__ ((used, section ("__OBJC, __meta_class")))= {(struct _objc_class *)"X", 0, "X", 0,2, sizeof(struct _objc_class), 0, (struct _objc_method_list *)&_OBJC_CLASS_METHODS_X,0,0,0,0};static struct _objc_class _OBJC_CLASS_X __attribute__ ((used, section ("__OBJC, __class")))= {&_OBJC_METACLASS_X, 0, "X", 0,1,0,0,0,0,0,0,0};struct _objc_symtab {long sel_ref_cnt;SEL *refs;short cls_def_cnt;short cat_def_cnt;void *defs[1];};static struct _objc_symtab _OBJC_SYMBOLS __attribute__((used, section ("__OBJC, __symbols")))= {0, 0, 1, 0,&_OBJC_CLASS_X};struct _objc_module {long version;long size;const char *name;struct _objc_symtab *symtab;};static struct _objc_module _OBJC_MODULES __attribute__ ((used, section ("__OBJC, __module_info")))= {7, sizeof(struct _objc_module), "", &_OBJC_SYMBOLS};
I have submitted a pull-request containing some basic testing code for Objective-C. A program is correctly generated, but without a runtime, it naturally does not work. (Related runtime functions cannot be found when the program is started.)To get a runtime to work, a list of classes and other runtime information is needed. In Objective-C (with Apple runtime's ABI) classes are described as structures tagged with __attribute__((used, section "__OBJC, __class")). There are more section names used.Any tips on how these can get exposed?
I think the actual problem might be that __attribute__((used)) is ignored. Can I somehow get Emscripten to obey this flag? And, when I do, how can I get the variables out?
Hmm, I have no idea what a section is.
section ("section-name")data and bss. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The section attribute specifies that a variable (or function) lives in a particular section. For example, this small program uses several specific section names:Use the section attribute with global variables and not local variables, as shown in the example.
You may use the section attribute with initialized or uninitialized global variables but the linker requires each object be defined once, with the exception that uninitialized variables tentatively go in the common (or bss) section and can be multiply “defined”. Using the section attribute changes what section the variable goes into and may cause the linker to issue an error if an uninitialized variable has multiple definitions. You can force a variable to be initialized with the -fno-common flag or the nocommon attribute.
Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.
What does that cause to happen in the .ll?
I think the actual problem might be that __attribute__((used)) is ignored. Can I somehow get Emscripten to obey this flag? And, when I do, how can I get the variables out?That should work, for example
void __attribute__((used)) waka() { printf("waka"); }is kept alive when I test it now.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Compiling the c file fails, is it missing some #Includes perhaps?
I wonder if the section stuff is not confusing us. Does it work if we remove the section stuff from the c code? (Because in my example the attribute did not have anything but used, that's why I am curious).
We could probably parse out the Section stuff I guess. But I wonder if we actually need it. What would we do with the information?
@"OBJC_CLASS_$_X" = global %struct._class_t { %struct._class_t* @"OBJC_METACLASS_$_X", %struct._class_t* null, %struct._objc_cache* @_objc_empty_cache, i8* (i8*, i8*)** @_objc_empty_vtable, %struct._class_ro_t* @"\01l_OBJC_CLASS_RO_$_X" }, section "__DATA, __objc_data", align 8
I wonder if the section stuff is not confusing us. Does it work if we remove the section stuff from the c code? (Because in my example the attribute did not have anything but used, that's why I am curious).
If I remove section stuff from .ll code, indeed, nothing still appears. See attachment.I've also tried removing just the section attribute on one of the static variables, and nothing appears.Could it be that linker stage of emscripten determines these static variables are unused and strips them out?
We could probably parse out the Section stuff I guess. But I wonder if we actually need it. What would we do with the information?I'm not sure, but the information itself is definitely needed by the runtime. Each .m file that contains a class definition would produce a static variable marked as "used" and "section(something)", and the runtime needs to know about each of these class definitions.I'm not sure how to go about exposing them in a natural way.Note that the current way of doing things is actually a major hack; ideally Emscripten should NOT go through the C stage. Clang is pretty familiar with Objective-C and the LLVM byte code that it spits out is quite different than the one obtained if we go through the C stage :-)
--