[pushed] Objective-C, Darwin : Update metadata section uses.

Message ID B1C952D3-9FF2-41E8-81CC-D6FD04BF056D@sandoe.co.uk
State New
Headers show
Series
  • [pushed] Objective-C, Darwin : Update metadata section uses.
Related show

Commit Message

Iain Sandoe Oct. 10, 2020, 4:15 p.m.
Hi,

Newer versions of ld64 are more picky about adherence to placement
rules for objective c metadata.  This adds protocol refs and uses
the ivar refs for all targets.

tested across the Darwin supported range (and on x86_64-linux)
pushed to master,
thanks
Iain

gcc/ChangeLog:

	* config/darwin-sections.def (objc2_data_section): New.
	(objc2_ivar_section): New.
	* config/darwin.c (darwin_objc2_section): Act on Protocol and
	ivar refs.

gcc/objc/ChangeLog:

	* objc-next-runtime-abi-02.c
	(next_runtime_abi_02_init_metadata_attributes): Make protocol
	refs a distinct section.
---
 gcc/config/darwin-sections.def      | 4 ++++
 gcc/config/darwin.c                 | 6 ++++++
 gcc/objc/objc-next-runtime-abi-02.c | 4 ++--
 3 files changed, 12 insertions(+), 2 deletions(-)

-- 
2.24.1

Patch

diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def
index d3251db9d89..65bf5ad37a0 100644
--- a/gcc/config/darwin-sections.def
+++ b/gcc/config/darwin-sections.def
@@ -201,6 +201,10 @@  DEF_SECTION (objc2_constant_string_object_section, 0,
 
 /* Additions for compatibility with later runtime conventions especially for
    sections containing strings.  */
+DEF_SECTION (objc2_data_section, 0, ".section __DATA, __data", 1)
+
+DEF_SECTION (objc2_ivar_section, 0, ".section __DATA, __objc_ivar", 1)
+
 DEF_SECTION (objc2_class_names_section, 0,
 	     ".section __TEXT, __objc_classname, cstring_literals", 1)
 
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 7eb288ec3f8..e101f8eb655 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1460,6 +1460,9 @@  darwin_objc2_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base)
 
   else if (!strncmp (p, "G2_META", 7) || !strncmp (p, "G2_CLAS", 7))
     return darwin_sections[objc2_classdefs_section];
+  else if (!strncmp (p, "V2_PCOL", 7))
+    return ld_uses_coal_sects ? darwin_sections[data_coal_section]
+			      : darwin_sections[objc2_data_section];
   else if (!strncmp (p, "V2_MREF", 7))
     return darwin_sections[objc2_message_refs_section];
   else if (!strncmp (p, "V2_CLRF", 7))
@@ -1495,6 +1498,9 @@  darwin_objc2_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base)
   else if (!strncmp (p, "V2_CSTR", 7))
     return darwin_sections[objc2_constant_string_object_section];
 
+  else if (!strncmp (p, "V2_IVRF", 7))
+    return darwin_sections[objc2_ivar_section];
+
   /* Not recognized, default.  */
   return base;
 }
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index b4019cd4fe0..6d1badc5f36 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -305,8 +305,8 @@  next_runtime_abi_02_init_metadata_attributes (void)
 
   meta_class = get_identifier ("G2_CLAS");
   meta_metaclass = get_identifier ("G2_META");
-  meta_category =
-  meta_protocol = meta_base;
+  meta_category = meta_base;
+  meta_protocol = get_identifier ("V2_PCOL");
 
   meta_clac_vars =
   meta_clai_vars = meta_base;