From patchwork Sat May 2 03:30:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tbsaunde+gcc@tbsaunde.org X-Patchwork-Id: 467184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 62CA6140316 for ; Sat, 2 May 2015 13:31:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=jm56WUXs; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id; q=dns; s=default; b=n/3Ua+JYA3REXC9 Te+F/Z0YGKI9aRd5j9FVu/ofUjF5Cv0qi0GWlKoMelP2U9sz6EYLRkevuKI2lgej +enPlJhAaPT0uNY18/lRVE9lFNcPns5q4eAhpcSp8M5JfhOhBoZV/tZBf4+12TgF mmqwIkl12OsduUx/HiglHGSFb+d0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id; s=default; bh=4p3HBCSGE7sbVS5ilOLWA 6+LTUU=; b=jm56WUXs+qSFz965GAocCdvtHpdyyXLPssXOhHtPEngsUv8Q+zAlA MwNMoxN3dNDEn9yEFrkJWJR9mMADiEPpGAIHt3ltPQMisY9iwStrFfFwu6wJmjib QnL4VFknAunLxmtwoPB855sJme8ds9Ddn0Qff0D7lzx1SPSStbZn3g= Received: (qmail 98534 invoked by alias); 2 May 2015 03:31:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 98521 invoked by uid 89); 2 May 2015 03:31:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD, URIBL_BLACK autolearn=no version=3.3.2 X-HELO: paperclip.tbsaunde.org Received: from tbsaunde.org (HELO paperclip.tbsaunde.org) (66.228.47.254) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 02 May 2015 03:31:43 +0000 Received: from iceball.corp.tor1.mozilla.com (unknown [66.207.208.102]) by paperclip.tbsaunde.org (Postfix) with ESMTPSA id 6DB53C0A2 for ; Sat, 2 May 2015 03:31:40 +0000 (UTC) From: tbsaunde+gcc@tbsaunde.org To: gcc-patches@gcc.gnu.org Subject: [PATCH] fixup libobjc usage of PCC_BITFIELD_TYPE_MATTERS Date: Fri, 1 May 2015 23:30:53 -0400 Message-Id: <1430537453-25556-1-git-send-email-tbsaunde+gcc@tbsaunde.org> X-IsSubscribed: yes From: Trevor Saunders Hi, This adds a configure check to libobjc to find out if types of bitfields effect their layout, and uses it to replace the rather broken usage of PCC_BITFIELD_TYPE_MATTERS. bootstrapped + regtested x86_64-linux-gnu, bootstrapped on ppc64le-linux-gnu and ran check-objc there without failures, and checked the correct part of the ifdef is used on a cross to m68k-linux-elf. ok? I'm sure I've gotten something wrong since this is a bunch of auto tools ;-) Trev libobjc/ChangeLog: 2015-05-01 Trevor Saunders * acinclude.m4: Include bitfields.m4. * config.h.in: Regenerate. * configure: Likewise. * configure.ac: Invoke gt_BITFIELD_TYPE_MATTERS. * encoding.c: Check HAVE_BITFIELD_TYPE_MATTERS. config/ChangeLog: 2015-05-01 Trevor Saunders * bitfields.m4: New file. --- config/bitfields.m4 | 26 ++++++++++++++++++++++++++ libobjc/acinclude.m4 | 1 + libobjc/config.h.in | 3 +++ libobjc/configure | 38 ++++++++++++++++++++++++++++++++++++++ libobjc/configure.ac | 2 ++ libobjc/encoding.c | 3 ++- 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 config/bitfields.m4 diff --git a/config/bitfields.m4 b/config/bitfields.m4 new file mode 100644 index 0000000..ee8f3b5 --- /dev/null +++ b/config/bitfields.m4 @@ -0,0 +1,26 @@ +dnl Copyright (C) 2015 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +# Define HAVE_BITFIELD_TYPE_MATTERS if the type of bitfields effects their +# alignment. + +AC_DEFUN([gt_BITFIELD_TYPE_MATTERS], +[ + AC_CACHE_CHECK([if the type of bitfields matters], gt_cv_bitfield_type_matters, + [ + AC_TRY_COMPILE( + [struct foo1 { char x; char :0; char y; }; +struct foo2 { char x; int :0; char y; }; +int foo1test[ sizeof (struct foo1) == 2 ? 1 : -1 ]; +int foo2test[ sizeof (struct foo2) == 5 ? 1 : -1]; ], + [], gt_cv_bitfield_type_matters=yes, gt_cv_bitfield_type_matters=no) + ]) + if test $gt_cv_bitfield_type_matters = yes; then + AC_DEFINE(HAVE_BITFIELD_TYPE_MATTERS, 1, + [Define if the type of bitfields effects alignment.]) + fi +]) diff --git a/libobjc/acinclude.m4 b/libobjc/acinclude.m4 index bf78dbe..4193018 100644 --- a/libobjc/acinclude.m4 +++ b/libobjc/acinclude.m4 @@ -12,6 +12,7 @@ m4_include(../config/acx.m4) m4_include(../config/no-executables.m4) m4_include(../config/enable.m4) m4_include(../config/tls.m4) +m4_include(../config/bitfields.m4) m4_include(../libtool.m4) dnl The lines below arrange for aclocal not to bring an installed diff --git a/libobjc/config.h.in b/libobjc/config.h.in index c055e7c..20d1fca 100644 --- a/libobjc/config.h.in +++ b/libobjc/config.h.in @@ -1,5 +1,8 @@ /* config.h.in. Generated from configure.ac by autoheader. */ +/* Define if the type of bitfields effects alignment. */ +#undef HAVE_BITFIELD_TYPE_MATTERS + /* Define to 1 if the target assembler supports thread-local storage. */ #undef HAVE_CC_TLS diff --git a/libobjc/configure b/libobjc/configure index 642eb9c..0547f91 100755 --- a/libobjc/configure +++ b/libobjc/configure @@ -11530,6 +11530,44 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_exception_model_name" >&5 $as_echo "$ac_exception_model_name" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the type of bitfields matters" >&5 +$as_echo_n "checking if the type of bitfields matters... " >&6; } +if test "${gt_cv_bitfield_type_matters+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +struct foo1 { char x; char :0; char y; }; +struct foo2 { char x; int :0; char y; }; +int foo1test[ sizeof (struct foo1) == 2 ? 1 : -1 ]; +int foo2test[ sizeof (struct foo2) == 5 ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + gt_cv_bitfield_type_matters=yes +else + gt_cv_bitfield_type_matters=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_bitfield_type_matters" >&5 +$as_echo "$gt_cv_bitfield_type_matters" >&6; } + if test $gt_cv_bitfield_type_matters = yes; then + +$as_echo "#define HAVE_BITFIELD_TYPE_MATTERS 1" >>confdefs.h + + fi + + # ------ # Output # ------ diff --git a/libobjc/configure.ac b/libobjc/configure.ac index c794a80..2d88519 100644 --- a/libobjc/configure.ac +++ b/libobjc/configure.ac @@ -266,6 +266,8 @@ fi AC_LANG_POP(C) AC_MSG_RESULT($ac_exception_model_name) +gt_BITFIELD_TYPE_MATTERS + # ------ # Output # ------ diff --git a/libobjc/encoding.c b/libobjc/encoding.c index 20ace46..abb6145 100644 --- a/libobjc/encoding.c +++ b/libobjc/encoding.c @@ -29,6 +29,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* FIXME: This file contains functions that will abort the entire program if they fail. Is that really needed ? */ +#include "config.h" #include "objc-private/common.h" #include "objc-private/error.h" #include "tconfig.h" @@ -1167,7 +1168,7 @@ objc_layout_structure_next_member (struct objc_struct_layout *layout) /* Record must have at least as much alignment as any field. Otherwise, the alignment of the field within the record is meaningless. */ -#if !PCC_BITFIELD_TYPE_MATTERS +#ifndef HAVE_BITFIELD_TYPE_MATTERS layout->record_align = MAX (layout->record_align, desired_align); #else /* PCC_BITFIELD_TYPE_MATTERS */ if (*type == _C_BFLD)