GCC Bugzilla – Bug 26427
with -fsection-anchors with zero sized structs
Last modified: 2011-01-10 20:26:19 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.
This causes a lot of the gfortran testsuite to fail.
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.
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
*** Bug 27683 has been marked as a duplicate of this bug. ***
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.
Created attachment 11532 [details] new patch which again works around darwin back-end mess
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?
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
(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.
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
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.
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.
Created attachment 11561 [details] corrected patch as provided by Andrew
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
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.
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
This should be fixed now.
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.
(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.
This has been worked arounded on the mainline.
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
fixed on trunk