From: Iain Sandoe Date: Sun, 4 Oct 2020 09:09:57 +0000 (+0100) Subject: Darwin, Objective-C : Adjust objective-c symbol linkage with version. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8703bf5d31fdb4789b5eddca394f8e92a0c55801;p=gcc.git Darwin, Objective-C : Adjust objective-c symbol linkage with version. Earlier linkers cannot handle publicly-visible (or linker-visible) metadata, so we need to make the output of these conditional on version. gcc/ChangeLog: * config/darwin.c (darwin_globalize_label): Make a subset of metadate symbols global. (darwin_label_is_anonymous_local_objc_name): Make a subset of metadata symbols linker-visible. (darwin_override_options): Track more target OS versions, make the next_runtime version track this (unless it's set to 0 for GNU runtime). gcc/objc/ChangeLog: * objc-next-runtime-abi-02.c (FIXUP_NEEDED): Rename ... (USE_FIXUP_BEFORE): ... to this. (next_runtime_02_initialize): Likewise. (next_runtime_abi_02_get_arg_type_list_base): Likewise. (next_runtime_abi_02_build_objc_method_call): Likewise. --- diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 33c6ce42c1b..dd4857f9e34 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -1876,7 +1876,10 @@ darwin_globalize_label (FILE *stream, const char *name) { if (!!strncmp (name, "_OBJC_", 6)) default_globalize_label (stream, name); - /* We have some Objective C cases that need to be global. */ + /* We have some Objective C cases that need to be global, but only on newer + OS versions. */ + if (flag_objc_abi < 2 || flag_next_runtime < 100700) + return; if (!strncmp (name+6, "LabelPro", 8)) default_globalize_label (stream, name); if (!strncmp (name+6, "Protocol_", 9)) @@ -1901,8 +1904,14 @@ darwin_label_is_anonymous_local_objc_name (const char *name) } if (strncmp ((const char *)p, "_OBJC_", 6) != 0) return false; + /* We need some of the objective c meta-data symbols to be visible to the - linker. FIXME: this is horrible, we need a better mechanism. */ + linker (when the target OS version is newer). FIXME: this is horrible, + we need a better mechanism. */ + + if (flag_objc_abi < 2 || flag_next_runtime < 100700) + return true; + p += 6; if (!strncmp ((const char *)p, "ClassRef", 8)) return false; @@ -3183,10 +3192,14 @@ darwin_override_options (void) /* Keep track of which (major) version we're generating code for. */ if (darwin_macosx_version_min) { - if (strverscmp (darwin_macosx_version_min, "10.6") >= 0) + if (strverscmp (darwin_macosx_version_min, "10.7") >= 0) + generating_for_darwin_version = 11; + else if (strverscmp (darwin_macosx_version_min, "10.6") >= 0) generating_for_darwin_version = 10; else if (strverscmp (darwin_macosx_version_min, "10.5") >= 0) generating_for_darwin_version = 9; + else if (strverscmp (darwin_macosx_version_min, "10.4") >= 0) + generating_for_darwin_version = 8; /* Earlier versions are not specifically accounted, until required. */ } @@ -3202,6 +3215,20 @@ darwin_override_options (void) should check for correctness re. the ABI. TODO: check and provide the flags (runtime & ABI) from the lto wrapper). */ + /* At present, make a hard update to the runtime version based on the target + OS version. */ + if (flag_next_runtime) + { + if (generating_for_darwin_version > 10) + flag_next_runtime = 100705; + else if (generating_for_darwin_version > 9) + flag_next_runtime = 100608; + else if (generating_for_darwin_version > 8) + flag_next_runtime = 100508; + else + flag_next_runtime = 100000; + } + /* Unless set, force ABI=2 for NeXT and m64, 0 otherwise. */ if (!global_options_set.x_flag_objc_abi) global_options.x_flag_objc_abi diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c index 0c7a600c597..60bf86ab8c9 100644 --- a/gcc/objc/objc-next-runtime-abi-02.c +++ b/gcc/objc/objc-next-runtime-abi-02.c @@ -69,7 +69,7 @@ along with GCC; see the file COPYING3. If not see #define TAG_MSGSENDID_STRET "objc_msgSendId_stret" #define TAG_MSGSENDSUPER_STRET "objc_msgSendSuper2_stret" -#define FIXUP_NEEDED 100600 +#define USE_FIXUP_BEFORE 100600 #define TAG_FIXUP "_fixup" @@ -392,7 +392,7 @@ static void next_runtime_02_initialize (void) build_v2_protocol_template (); build_v2_category_template (); - bool fixup_p = flag_next_runtime < FIXUP_NEEDED; + bool fixup_p = flag_next_runtime < USE_FIXUP_BEFORE; if (fixup_p) { /* id objc_msgSend_fixup_rtp (id, struct message_ref_t*, ...); */ @@ -1151,7 +1151,7 @@ next_runtime_abi_02_get_arg_type_list_base (vec **argtypes, receiver_type = objc_object_type; vec_safe_push (*argtypes, receiver_type); - if (flag_next_runtime < FIXUP_NEEDED) + if (flag_next_runtime < USE_FIXUP_BEFORE) /* Selector type - will eventually change to `int'. */ vec_safe_push (*argtypes, superflag ? objc_v2_super_selector_type : objc_v2_selector_type); @@ -1821,7 +1821,7 @@ next_runtime_abi_02_build_objc_method_call (location_t loc, && TREE_TYPE (receiver) == objc_class_type)) check_for_nil = false; - if (flag_next_runtime >= FIXUP_NEEDED) + if (flag_next_runtime >= USE_FIXUP_BEFORE) { tree selector = next_runtime_abi_02_build_selector_reference (loc, sel_name,