Skip to content

Commit

Permalink
Remove GCC ABI from abi versions
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Sep 8, 2024
1 parent 2e918b4 commit 9796196
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 131 deletions.
7 changes: 2 additions & 5 deletions abi_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct objc_abi_version

enum
{
gcc_abi = 8,
gnustep_abi = 9,
gc_abi = 10
};
Expand All @@ -42,12 +41,10 @@ enum
*/
static struct objc_abi_version known_abis[] =
{
/* GCC ABI. */
{gcc_abi, gcc_abi, gnustep_abi, sizeof(struct objc_module_abi_8)},
/* Non-fragile ABI. */
{gnustep_abi, gcc_abi, gc_abi, sizeof(struct objc_module_abi_8)},
{gnustep_abi, gnustep_abi, gc_abi, sizeof(struct objc_module_abi_8)},
/* GC ABI. Adds a field describing the GC mode. */
{gc_abi, gcc_abi, gc_abi, sizeof(struct objc_module_abi_10)}
{gc_abi, gnustep_abi, gc_abi, sizeof(struct objc_module_abi_10)}
};

static int known_abi_count =
Expand Down
42 changes: 21 additions & 21 deletions category.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ struct objc_category
struct objc_property_list *class_properties;
};

struct objc_category_gcc
struct objc_category_gsv1
{
/**
* The name of this category.
*/
const char *name;
/**
* The name of the class to which this category should be applied.
*/
const char *class_name;
/**
* The list of instance methods to add to the class.
*/
struct objc_method_list_gcc *instance_methods;
/**
* The list of class methods to add to the class.
*/
struct objc_method_list_gcc *class_methods;
/**
* The list of protocols adopted by this category.
*/
struct objc_protocol_list *protocols;
/**
* The name of this category.
*/
const char *name;
/**
* The name of the class to which this category should be applied.
*/
const char *class_name;
/**
* The list of instance methods to add to the class.
*/
struct objc_method_list_gsv1 *instance_methods;
/**
* The list of class methods to add to the class.
*/
struct objc_method_list_gsv1 *class_methods;
/**
* The list of protocols adopted by this category.
*/
struct objc_protocol_list *protocols;
};
27 changes: 2 additions & 25 deletions class.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ struct objc_class_gsv1
/**
* Metadata describing the instance variables in this class.
*/
struct objc_ivar_list_gcc *ivars;
struct objc_ivar_list_gsv1 *ivars;
/**
* Metadata for for defining the mappings from selectors to IMPs. Linked
* list of method list structures, one per class and one per category.
*/
struct objc_method_list_gcc *methods;
struct objc_method_list_gsv1 *methods;
/**
* The dispatch table for this class. Intialized and maintained by the
* runtime.
Expand Down Expand Up @@ -274,29 +274,6 @@ struct objc_class_gsv1
uintptr_t weak_pointers;
};

/**
* Structure representing the GCC ABI class structure. This is only ever
* required so that we can take its size - struct objc_class begins with the
* same fields, and you can test the new abi flag to tell whether it is safe to
* access the subsequent fields.
*/
struct objc_class_gcc
{
Class isa;
Class super_class;
const char *name;
long version;
unsigned long info;
long instance_size;
struct objc_ivar_list_gcc *ivars;
struct objc_method_list *methods;
void *dtable;
Class subclass_list;
Class sibling_class;
struct objc_protocol_list *protocols;
void *gc_object_type;
};


/**
* An enumerated type describing all of the valid flags that may be used in the
Expand Down
6 changes: 3 additions & 3 deletions ivar.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static inline objc_ivar_ownership ivarGetOwnership(Ivar ivar)
/**
* Legacy ivar structure, inherited from the GCC ABI.
*/
struct objc_ivar_gcc
struct objc_ivar_gsv1
{
/**
* Name of this instance variable.
Expand Down Expand Up @@ -189,7 +189,7 @@ static inline struct objc_ivar *ivar_at_index(struct objc_ivar_list *l, int i)
/**
* Legacy version of the ivar list
*/
struct objc_ivar_list_gcc
struct objc_ivar_list_gsv1
{
/**
* The number of instance variables in this list.
Expand All @@ -199,6 +199,6 @@ struct objc_ivar_list_gcc
* An array of instance variable metadata structures. Note that this array
* has count elements.
*/
struct objc_ivar_gcc ivar_list[];
struct objc_ivar_gsv1 ivar_list[];
};

44 changes: 12 additions & 32 deletions legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static objc_ivar_ownership ownershipForIvar(struct objc_class_gsv1 *cls, int idx

static struct objc_ivar_list *upgradeIvarList(struct objc_class_gsv1 *cls)
{
struct objc_ivar_list_gcc *l = cls->ivars;
struct objc_ivar_list_gsv1 *l = cls->ivars;
if (l == NULL)
{
return NULL;
Expand Down Expand Up @@ -135,7 +135,7 @@ static struct objc_ivar_list *upgradeIvarList(struct objc_class_gsv1 *cls)
return n;
}

static struct objc_method_list *upgradeMethodList(struct objc_method_list_gcc *old)
static struct objc_method_list *upgradeMethodList(struct objc_method_list_gsv1 *old)
{
if (old == NULL)
{
Expand Down Expand Up @@ -322,8 +322,8 @@ static struct objc_property_list *upgradePropertyList(struct objc_property_list_
{
return NULL;
}
size_t ARRAY_DATA_SIZE = l->count * sizeof(struct objc_property);
struct objc_property_list *n = calloc(1, sizeof(struct objc_property_list) + ARRAY_DATA_SIZE);
size_t data_size = l->count * sizeof(struct objc_property);
struct objc_property_list *n = calloc(1, sizeof(struct objc_property_list) + data_size);
n->count = l->count;
n->size = sizeof(struct objc_property);
for (int i=0 ; i<l->count ; i++)
Expand Down Expand Up @@ -367,10 +367,11 @@ PRIVATE Class objc_upgrade_class(struct objc_class_gsv1 *oldClass)
}
return cls;
}
PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gcc *old)

PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gsv1 *old)
{
struct objc_category *cat = calloc(1, sizeof(struct objc_category));
memcpy(cat, old, sizeof(struct objc_category_gcc));
memcpy(cat, old, sizeof(struct objc_category_gsv1));
cat->instance_methods = upgradeMethodList(old->instance_methods);
cat->class_methods = upgradeMethodList(old->class_methods);
if (cat->instance_methods != NULL)
Expand All @@ -389,7 +390,7 @@ PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gcc *ol
}

static struct objc_protocol_method_description_list*
upgrade_protocol_method_list_gcc(struct objc_protocol_method_description_list_gcc *l)
upgrade_protocol_method_list_gsv1(struct objc_protocol_method_description_list_gsv1 *l)
{
if ((l == NULL) || (l->count == 0))
{
Expand All @@ -408,27 +409,6 @@ upgrade_protocol_method_list_gcc(struct objc_protocol_method_description_list_gc
return n;
}

PRIVATE struct objc_protocol *objc_upgrade_protocol_gcc(struct objc_protocol_gcc *p)
{
// If the protocol has already been upgraded, the don't try to upgrade it twice.
if (p->isa == objc_getClass("ProtocolGCC"))
{
return objc_getProtocol(p->name);
}
p->isa = objc_getClass("ProtocolGCC");
Protocol *proto =
(Protocol*)class_createInstance((Class)objc_getClass("Protocol"),
sizeof(struct objc_protocol) - sizeof(id));
proto->name = p->name;
// Aliasing of this between the new and old structures means that when this
// returns these will all be updated.
proto->protocol_list = p->protocol_list;
proto->instance_methods = upgrade_protocol_method_list_gcc(p->instance_methods);
proto->class_methods = upgrade_protocol_method_list_gcc(p->class_methods);
assert(proto->isa);
return proto;
}

PRIVATE struct objc_protocol *objc_upgrade_protocol_gsv1(struct objc_protocol_gsv1 *p)
{
// If the protocol has already been upgraded, the don't try to upgrade it twice.
Expand All @@ -439,19 +419,19 @@ PRIVATE struct objc_protocol *objc_upgrade_protocol_gsv1(struct objc_protocol_gs
Protocol *n =
(Protocol*)class_createInstance((Class)objc_getClass("Protocol"),
sizeof(struct objc_protocol) - sizeof(id));
n->instance_methods = upgrade_protocol_method_list_gcc(p->instance_methods);
n->instance_methods = upgrade_protocol_method_list_gsv1(p->instance_methods);
// Aliasing of this between the new and old structures means that when this
// returns these will all be updated.
n->name = p->name;
n->protocol_list = p->protocol_list;
n->class_methods = upgrade_protocol_method_list_gcc(p->class_methods);
n->class_methods = upgrade_protocol_method_list_gsv1(p->class_methods);
n->properties = upgradePropertyList(p->properties);
n->optional_properties = upgradePropertyList(p->optional_properties);
n->isa = objc_getClass("Protocol");
// We do in-place upgrading of these, because they might be referenced
// directly
p->instance_methods = (struct objc_protocol_method_description_list_gcc*)n->instance_methods;
p->class_methods = (struct objc_protocol_method_description_list_gcc*)n->class_methods;
p->instance_methods = (struct objc_protocol_method_description_list_gsv1*)n->instance_methods;
p->class_methods = (struct objc_protocol_method_description_list_gsv1*)n->class_methods;
p->properties = (struct objc_property_list_gsv1*)n->properties;
p->optional_properties = (struct objc_property_list_gsv1*)n->optional_properties;
p->isa = objc_getClass("ProtocolGSv1");
Expand Down
6 changes: 1 addition & 5 deletions legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "protocol.h"

PRIVATE Class objc_upgrade_class(struct objc_class_gsv1 *oldClass);
PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gcc *);

PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gsv1 *old);
PRIVATE struct objc_class_gsv1* objc_legacy_class_for_class(Class);

PRIVATE struct objc_protocol *objc_upgrade_protocol_gcc(struct objc_protocol_gcc*);
PRIVATE struct objc_protocol *objc_upgrade_protocol_gsv1(struct objc_protocol_gsv1*);

8 changes: 4 additions & 4 deletions method.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct objc_method
};
// end: objc_method

struct objc_method_gcc
struct objc_method_gsv1
{
/**
* Selector used to send messages to this method. The type encoding of
Expand Down Expand Up @@ -86,18 +86,18 @@ static inline struct objc_method *method_at_index(struct objc_method_list *l, in
/**
* Legacy version of the method list.
*/
struct objc_method_list_gcc
struct objc_method_list_gsv1
{
/**
* The next group of methods in the list.
*/
struct objc_method_list_gcc *next;
struct objc_method_list_gsv1 *next;
/**
* The number of methods in this list.
*/
int count;
/**
* An array of methods. Note that the actual size of this is count.
*/
struct objc_method_gcc methods[];
struct objc_method_gsv1 methods[];
};
24 changes: 2 additions & 22 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ static id incompleteProtocolClass(void)
return IncompleteProtocolClass;
}

/**
* Class used for legacy GCC protocols (`ProtocolGCC`).
*/
static id protocol_class_gcc;
/**
* Class used for legacy GNUstep V1 ABI protocols (`ProtocolGSv1`).
*/
Expand All @@ -72,10 +68,6 @@ static id protocol_class_gsv2;

static BOOL init_protocol_classes(void)
{
if (nil == protocol_class_gcc)
{
protocol_class_gcc = objc_getClass("ProtocolGCC");
}
if (nil == protocol_class_gsv1)
{
protocol_class_gsv1 = objc_getClass("ProtocolGSv1");
Expand All @@ -84,8 +76,7 @@ static BOOL init_protocol_classes(void)
{
protocol_class_gsv2 = objc_getClass("Protocol");
}
if ((nil == protocol_class_gcc) ||
(nil == protocol_class_gsv1) ||
if ((nil == protocol_class_gsv1) ||
(nil == protocol_class_gsv2))
{
return NO;
Expand All @@ -108,10 +99,6 @@ static BOOL protocol_hasOptionalMethodsAndProperties(struct objc_protocol *p)
{
return NO;
}
if (p->isa == protocol_class_gcc)
{
return NO;
}
return YES;
}

Expand Down Expand Up @@ -207,8 +194,7 @@ static BOOL init_protocols(struct objc_protocol_list *protocols)
{
struct objc_protocol *aProto = protocols->list[i];
// Don't initialise a protocol twice
if ((aProto->isa == protocol_class_gcc) ||
(aProto->isa == protocol_class_gsv1) ||
if ((aProto->isa == protocol_class_gsv1) ||
(aProto->isa == protocol_class_gsv2))
{
continue;
Expand All @@ -224,12 +210,6 @@ static BOOL init_protocols(struct objc_protocol_list *protocols)
fprintf(stderr, "Unknown protocol version");
abort();
#ifdef OLDABI_COMPAT
case protocol_version_gcc:
protocols->list[i] = objc_upgrade_protocol_gcc((struct objc_protocol_gcc *)aProto);
assert(aProto->isa == protocol_class_gcc);
assert(protocols->list[i]->isa == protocol_class_gsv2);
aProto = protocols->list[i];
break;
case protocol_version_gsv1:
protocols->list[i] = objc_upgrade_protocol_gsv1((struct objc_protocol_gsv1 *)aProto);
assert(aProto->isa == protocol_class_gsv1);
Expand Down
Loading

0 comments on commit 9796196

Please sign in to comment.