Bug 26427 - with -fsection-anchors with zero sized structs
: with -fsection-anchors with zero sized structs
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: target
: 4.2.0
: P2 normal
: ---
Assigned To: Not yet assigned to anyone
:
: wrong-code
:
:
  Show dependency treegraph
 
Reported: 2006-02-22 18:58 UTC by Andrew Pinski
Modified: 2011-01-10 20:26 UTC (History)
8 users (show)

See Also:
Host:
Target: powerpc-darwin
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-02-23 09:01:26


Attachments
patch which fixes part of the problem (2.29 KB, patch)
2006-05-27 04:11 UTC, Andrew Pinski
Details | Diff
new patch which again works around darwin back-end mess (1015 bytes, patch)
2006-05-29 21:06 UTC, Andrew Pinski
Details | Diff
corrected patch as provided by Andrew (1.10 KB, text/plain)
2006-06-01 00:05 UTC, Jack Howarth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2006-02-22 18:58:03 UTC
Testcase:
struct a {};
static const int d = 1;
static const struct a b = {};
static const int c = 1;
int f(const int *, const struct a *, const int*, const int*);
int g(void)
{
  return f(&c, &b, &d, &c);
}
int f(const int *b, const struct a *c, const int *d, const int *e)
{
  return *b == *d;
}
int main(void)
{
  if (!g())
    __builtin_abort();
}

-----
What is happening is that the size for b is being calcuated wrong in the anchor
code, I don't know how to fix this yet.
Comment 1 Andrew Pinski 2006-02-22 19:00:12 UTC
This causes a lot of the gfortran testsuite to fail.
Comment 2 rsandifo@gcc.gnu.org 2006-02-23 09:01:26 UTC
In keeping with your choice of "target" category, I think this is a
Darwin-specific thing.  ASM_DECLARE_OBJECT_NAME() in config/darwin.h says:

    /* Darwin doesn't support zero-size objects, so give them a        \
       byte.  */                            \
    if (tree_low_cst (DECL_SIZE_UNIT (DECL), 1) == 0)            \
      assemble_zeros (1);                        \

Adding extra data behind varasm's back is going to play havoc with
any attempt to place objects correctly.

I'm considering adding equivalent code to varasm.c.  This will fix
an inconsistency in the handling of zero-sized decls: sometimes
they get a byte of storage allocated to them (giving them a unique
address) and sometimes they don't.

If the patch works out, I'll remove the code above.  Not assigning
myself until I get further though.
Comment 3 rsandifo@gcc.gnu.org 2006-03-02 19:44:24 UTC
I said:

> I'm considering adding equivalent code to varasm.c.  This will fix
> an inconsistency in the handling of zero-sized decls: sometimes
> they get a byte of storage allocated to them (giving them a unique
> address) and sometimes they don't.

I'm no longer sure that's a good idea.  I suspect some users of
zero-sized structs really do want them to take zero size in the
object, and know which incantation they need to get that.

I'll have to leave the darwin.h ASM_DECLARE_OBJECT_NAME() issue
to someone with access to Darwin.

Richard
Comment 4 Andrew Pinski 2006-05-27 02:27:01 UTC
*** Bug 27683 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2006-05-27 04:11:17 UTC
Created attachment 11517 [details]
patch which fixes part of the problem

This fixes the C testcase but it does not fix the Fortran issue but I don't
think the fortran issue is a target back-end issue now since
darwin_use_anchors_for_symbol_p does return false for the rtx.  I am off to the
bar for tonight so I cannot test this or fix the fortran issue.
Comment 6 Andrew Pinski 2006-05-29 21:06:52 UTC
Created attachment 11532 [details]
new patch which again works around darwin back-end mess
Comment 7 Andrew Pinski 2006-05-29 21:08:10 UTC
Mike since you approved my orginal patch to fix some of -fsection-anchors and I
reported this bug back with that patch, could you look into fixing this?
Comment 8 Jack Howarth 2006-05-29 23:04:33 UTC
Andrew,
    I assume the new revised patch still only addresses the original PR 26427
test case
and doesn't resolve the gfortran testsuite failures in PR 27683. If PR 27683
isn't really
a duplicate of PR 26427 as you originally thought, shouldn't PR 27683 be
reopened?
         Jack
Comment 9 Andrew Pinski 2006-05-29 23:10:31 UTC
(In reply to comment #8)
Jack, it resolves both but it is just a hack around the fact that Darwin
back-end goes behind the middle-end to change the size of the
structs/arrays/string_csts to 1 from zero.
Comment 10 Jack Howarth 2006-05-31 01:44:28 UTC
Andrew,
   I can confirm that the proposed patch (with the missing null check) resolves
the new gfortran
failures on Darwin. Could you update the patch in this PR to revised version
with the null check
though. Hopefully we can get this into the trunk soon.
           Jack
Comment 11 Mike Stump 2006-05-31 22:32:01 UTC
I have a patch:

http://gcc.gnu.org/ml/gcc-patches/2006-05/msg01580.html

that I think fixes this problem.  I'd be cusious to hear if it fixes the
Fortran problem for you.
Comment 12 Geoff Keating 2006-05-31 22:48:39 UTC
The issue here is that Darwin does not support zero-sized objects in the
linker.  It just won't work.

So, you need to make sure that the linker never sees them.  This is presently
done for Darwin by adding a byte of padding at the end of every zero-sized
object.  Note that from the user's point of view, the structure is still zero
size; sizeof() will return 0.

If varasm.c needs to know about this, then this logic should move there.
Comment 13 Jack Howarth 2006-06-01 00:05:29 UTC
Created attachment 11561 [details]
corrected patch as provided by Andrew
Comment 14 Jack Howarth 2006-06-01 00:21:54 UTC
Geoff,
    Then I assume you approve of Andrew Pinski's fix? I have uploaded the
corrected patch
that Andrew sent me which solves this problem in varasm.c. Or did you have a
different
approach in mind?
           Jack
Comment 15 Geoff Keating 2006-06-01 21:49:16 UTC
After discussion with Mike, I don't think Andrew's fix is right either.

If varasm.c wants to be able to predict memory layout, then what it needs to do
is ensure that the memory layout is seen as a single unit by the linker.  This
can only be done by ensuring that the layout contains no linker-visible labels,
that is all the labels inside the layout must start with 'L'.  If this is done,
then the linker is not involved and zero-sized objects can be zero sized.
Comment 16 mrs@gcc.gnu.org 2006-06-08 22:23:25 UTC
Subject: Bug 26427

Author: mrs
Date: Thu Jun  8 22:23:17 2006
New Revision: 114498

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114498
Log:
    PR target/26427
    * config/darwin.c (darwin_asm_output_anchor): Disable
    -fsection-anchors on darwin for now.
    * config/darwin.h (TARGET_ASM_OUTPUT_ANCHOR): Likewise.
    * rs6000/rs6000.c (optimization_options): Likewise.

testsuite:
    * gcc.dg/pr26427.c: Test to ensure that -fsection-anchors doesn't
    produce bad code on darwin.

Added:
    trunk/gcc/testsuite/gcc.dg/pr26427.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/darwin.c
    trunk/gcc/config/darwin.h
    trunk/gcc/config/rs6000/rs6000.c
    trunk/gcc/testsuite/ChangeLog
Comment 17 Mike Stump 2006-06-08 22:26:02 UTC
This should be fixed now.
Comment 18 Mike Stump 2006-06-08 22:40:08 UTC
The regression was introduced by:

2006-04-30  David Edelsohn  <edelsohn@gnu.org>

        * config/rs6000/rs6000.c (rs6000_override_options): Enable
        TARGET_NO_FP_IN_TOC for section anchors.
        (optimization_options): Enable section anchors for all
        non-"Objective" languages.
Comment 19 Andrew Pinski 2006-06-08 22:45:22 UTC
(In reply to comment #18)
> The regression was introduced by:
Exposed by and not introduced.  If you look at my patch which you approved, I
had mentioned this failure when I fixed most of -fsection-anchors for Darwin.
Comment 20 Andrew Pinski 2006-06-29 18:58:28 UTC
This has been worked arounded on the mainline.
Comment 21 Iain Sandoe 2010-11-29 14:58:23 UTC
Author: iains
Date: Mon Nov 29 14:58:16 2010
New Revision: 167242

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167242
Log:

    PR target/26427
    PR target/33120
    PR testsuite/35710

gcc:
    * config/i386/darwin.h (ASM_OUTPUT_COMMON): Remove
    (ASM_OUTPUT_LOCAL): Likewise.
    * config/darwin-protos.h (darwin_asm_declare_object_name): New.
    (darwin_output_aligned_bss): Likewise.
    (darwin_asm_output_aligned_decl_local): Likewise.
    (darwin_asm_output_aligned_decl_common): Likewise.
    (darwin_use_anchors_for_symbol_p): Likewise.
    * config/rs6000/darwin.h (ASM_OUTPUT_COMMON): Remove.
    (TARGET_ASM_OUTPUT_ANCHOR): Define.
    (TARGET_USE_ANCHORS_FOR_SYMBOL_P): Define.
    (DARWIN_SECTION_ANCHORS): Set to 1.
    * config/darwin.c (emit_aligned_common): New var.
    (darwin_init_sections): Check that the Darwin private zero-size section
    marker is in range.
    (darwin_text_section): Check for zero-sized objects.
    (darwin_mergeable_string_section): Likewise.
    (darwin_mergeable_constant_section): Likewise.
    (machopic_select_section): Adjust to check for zero-sized objects.
    Assert that OBJC meta data are non-zero sized.
    (darwin_asm_declare_object_name): New.
    (darwin_asm_declare_constant_name): Adjust for zero-sized
    object sections.
    (BYTES_ZFILL): Define.
    (darwin_emit_weak_or_comdat): New.
    (darwin_emit_local_bss): New.
    (darwin_emit_common): New.
    (darwin_output_aligned_bss): New.
    (darwin_asm_output_aligned_decl_common): New.
    (darwin_asm_output_aligned_decl_local): New.
    (darwin_file_end): Disable subsections_via_symbols when section
    anchoring is active.
    (darwin_asm_output_anchor): Re-enable.
    (darwin_use_anchors_for_symbol_p): New.
    (darwin_override_options): Check for versions that can emit
    aligned common.  Update usage of flags to current.
    * config/darwin-sections.def: Update comments and flags for
    non-anchor sections.  zobj_const_section, zobj_data_section,
    zobj_bss_section, zobj_const_data_section: New.
    * config/darwin.h (ASM_DECLARE_OBJECT_NAME): Redefine.
    (ASM_OUTPUT_ALIGN): Make whitespace output consistent.
    (L2_MAX_OFILE_ALIGNMENT): Define.
    (ASM_OUTPUT_ALIGNED_BSS): Define.
    (ASM_OUTPUT_ALIGNED_DECL_LOCAL): Define.
    (ASM_OUTPUT_ALIGNED_DECL_COMMON): Define.
    (SECTION_NO_ANCHOR): Define.
    (TARGET_ASM_OUTPUT_ANCHOR) Define with a default of NULL.
    (DARWIN_SECTION_ANCHORS): Define with a default of 0.

boehm-gc:
    * dyn_load.c (GC_register_dynamic_libraries/DARWIN):  Add new writable
    data section names.
    (GC_dyld_name_for_hdr): Adjust layout.
    (GC_dyld_image_add): Adjust layout, add new Darwin sections, adjust
    debug to name the sections.
    (GC_dyld_image_remove): Adjust layout, remove new Darwin sections,
    adjust debug to name the sections.
    (GC_register_dynamic_libraries): Adjust layout.
    (GC_init_dyld): Likewise.
    (GC_register_main_static_data): Likewise.

gcc/testsuite:
    * gcc.target/powerpc/darwin-abi-12.c: Adjust for new allocators.
    * gcc.dg/pr26427.c: Remove redundant warning for powerpc.
    * gcc.dg/darwin-comm.c: Adjust for new allocators.
    * gcc.dg/darwin-sections.c: New test.
    * g++.dg/ext/instantiate2.C: Adjust for new allocators.


Added:
    trunk/gcc/testsuite/gcc.dg/darwin-sections.c
Modified:
    trunk/boehm-gc/ChangeLog
    trunk/boehm-gc/dyn_load.c
    trunk/gcc/ChangeLog
    trunk/gcc/config/darwin-protos.h
    trunk/gcc/config/darwin-sections.def
    trunk/gcc/config/darwin.c
    trunk/gcc/config/darwin.h
    trunk/gcc/config/i386/darwin.h
    trunk/gcc/config/rs6000/darwin.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/ext/instantiate2.C
    trunk/gcc/testsuite/gcc.dg/darwin-comm.c
    trunk/gcc/testsuite/gcc.dg/pr26427.c
    trunk/gcc/testsuite/gcc.target/powerpc/darwin-abi-12.c
Comment 22 Iain Sandoe 2011-01-10 20:26:19 UTC
fixed on trunk