public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-10-branch)] Darwin: Handle NULL DECL_SIZE_TYPE in machopic_select_section (PR94237).
@ 2020-03-25 10:09 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-03-25 10:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dfb25dfe3d34703f6e493664831dfaf53672b07b

commit dfb25dfe3d34703f6e493664831dfaf53672b07b
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sat Mar 21 13:20:47 2020 +0000

    Darwin: Handle NULL DECL_SIZE_TYPE in machopic_select_section (PR94237).
    
    A recent change in the LTO streaming arrangement means that it is
    now possible for machopic_select_section () to be called with a NULL
    value for DECL_SIZE_TYPE - corresponding to an incomplete or not-yet-
    laid out type.
    
    When section anchors are present, and we are generating assembler, we
    normally need to know the object size when choosing the section, since
    zero-sized objects must be placed in sections that forbid section
    anchors.
    
    In the current circumstance, the objective of the earlier streaming of
    this data is to allow nm to determine BSS c.f. Data symbols (when used
    with the LTO plugin).  Since Darwin does not yet make use of the plugin
    this fix is a bit of future-proofing.  We now emit the 'generic' section
    for the decl (absent knowing its size) - which will still be correct in
    determining the BSS c.f. Data case.
    
    gcc/ChangeLog:
    
    2020-03-21  Iain Sandoe  <iain@sandoe.co.uk>
    
            PR lto/94237
            * config/darwin.c (darwin_mergeable_constant_section): Collect
            section anchor checks into the caller.
            (machopic_select_section): Collect section anchor checks into
            the determination of 'effective zero-size' objects.  When the
            size is unknown, assume it is non-zero, and thus return the
            'generic' section for the DECL.

Diff:
---
 gcc/ChangeLog       |  9 +++++++++
 gcc/config/darwin.c | 29 +++++++++++++++++++----------
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ba619c240d3..b691ac991bd 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2020-03-21 Iain Sandoe <iain@sandoe.co.uk>
+
+	* config/darwin.c (darwin_mergeable_constant_section): Collect
+	section anchor checks into the caller.
+	(machopic_select_section): Collect section anchor checks into
+	the determination of 'effective zero-size' objects. When the
+	size is unknown, assume it is non-zero, and thus return the
+	'generic' section for the DECL.
+
 2020-03-21 Iain Sandoe <iain@sandoe.co.uk>
 
 	PR target/93694
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 8131361715b..d3c0af8a4b6 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1354,9 +1354,7 @@ darwin_mergeable_constant_section (tree exp,
   machine_mode mode = DECL_MODE (exp);
   unsigned int modesize = GET_MODE_BITSIZE (mode);
 
-  if (DARWIN_SECTION_ANCHORS
-      && flag_section_anchors
-      && zsize)
+  if (zsize)
     return darwin_sections[zobj_const_section];
 
   if (flag_merge_constants
@@ -1586,8 +1584,23 @@ machopic_select_section (tree decl,
 	  && DECL_WEAK (decl)
 	  && !lookup_attribute ("weak_import", DECL_ATTRIBUTES (decl)));
 
-  zsize = (DECL_P (decl)
+  /* Darwin pads zero-sized objects with at least one byte, so that the ld64
+     atom model is preserved (objects must have distinct regions starting with
+     a unique linker-visible symbol).
+     In order to support section anchors, we need to move objects with zero
+     size into sections which are marked as "no section anchors"; the padded
+     objects, obviously, have real sizes that differ from their DECL sizes.  */
+  zsize = DARWIN_SECTION_ANCHORS && flag_section_anchors;
+
+  /* In the streaming of LTO symbol data, we might have a situation where the
+     var is incomplete or layout not finished (DECL_SIZE_UNIT is NULL_TREE).
+     We cannot tell if it is zero-sized then, but we can get the section
+     category correct so that nm reports the right kind of section
+     (e.g. BSS c.f. data).  */
+  zsize = (zsize
+	   && DECL_P (decl)
 	   && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
+	   && DECL_SIZE_UNIT (decl)
 	   && tree_to_uhwi (DECL_SIZE_UNIT (decl)) == 0);
 
   one = DECL_P (decl)
@@ -1635,15 +1648,11 @@ machopic_select_section (tree decl,
 	  else
 	    base_section = darwin_sections[data_coal_section];
 	}
-      else if (DARWIN_SECTION_ANCHORS
-	       && flag_section_anchors
-	       && zsize)
+      else if (zsize)
 	{
 	  /* If we're doing section anchors, then punt zero-sized objects into
 	     their own sections so that they don't interfere with offset
-	     computation for the remaining vars.  This does not need to be done
-	     for stuff in mergeable sections, since these are ineligible for
-	     anchors.  */
+	     computation for the remaining vars.  */
 	  if (ro)
 	    base_section = darwin_sections[zobj_const_data_section];
 	  else


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-25 10:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-25 10:09 [gcc(refs/vendors/redhat/heads/gcc-10-branch)] Darwin: Handle NULL DECL_SIZE_TYPE in machopic_select_section (PR94237) Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).