From patchwork Thu Oct 19 21:00:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 116436 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp932890qgn; Thu, 19 Oct 2017 14:01:00 -0700 (PDT) X-Received: by 10.159.206.198 with SMTP id x6mr2434950plo.35.1508446860669; Thu, 19 Oct 2017 14:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508446860; cv=none; d=google.com; s=arc-20160816; b=LnocLNrTK1YbSIfj25+t5YQMO6AraaWVImTp+AU68lpu7NHuJEf0nA+5r/b652/S2d 6Lc0g3fzzo+CxM9rjO5LZcHW/borcTFfxsZybQ7rYvMwIVwyhfP8wmAb7kMDAtAju+ED zXKxOo2N0xPwfgoMKFPVMCjNbPPu4vo9MC5jmn2sUd8cpX6cvCfgCkKL2meccZH+1/3v iHOZGglTUuV9JNTvXxKYGADZ3QWjYznmCEISK44pndkLq89d996ooOlHF4y//hLvU/zN Mbk2I4xC6w6g2adjST4jLT8VLKc+t4EmUNFN7eP72J/J1RXoTijHiUf7Pyex0oXoPvOD AxqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=vcLy6mTbmx3qTJFjc/XbTmoN3uvrsvc2sIYM9GajkvE=; b=aDRk1/MNwLDwsxxaW/u/yv8IIf8DclxGKvMT6Z3wdTZWy6Uupn7AhU1uYkZRx5hn6P Z2Tsa75bNEuGE/eY3cEdHK6mFlDGGLhPj839vIS76ITULO6/jK7jaSdil7gzp7pRxkLc B9vE8UDWGm/OBZW4sjhIu2rTD+s683xIXvjc6L6RPQiyqHw4EtdxJ/7xEvniPLQLNFXt TFfkX+9r3mITqDrplw6VAuLWg2DHPzvbMivha0yF33jU6OhRzOEK36jduXAgj6TiNYRG SHr60EdbaB8UwHxN29RS4ZLS78schQLxioc0oDyBo7S+cgIrAoV7NxI3FkZtftlVFDjP fwwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qzZhMrdW; spf=pass (google.com: domain of libc-alpha-return-86151-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-86151-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p73si9876716pfi.83.2017.10.19.14.01.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Oct 2017 14:01:00 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-86151-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qzZhMrdW; spf=pass (google.com: domain of libc-alpha-return-86151-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-86151-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=CgNMAy2S0o+GoiA/NTcH0brqUrZgMYb p7we08tC0ylz51O+jmb4V+ojyhpvKO3cNiIzBdPVEWrI4xraS1hdhpU/GqlW9F3D m6RohlbYD7Rv4NgCxR4SCdfMgItuxepMhm3nqUHrU5iVOVQrWbdaR3UA4jEfH4LL zfrPoAxR2IbA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=ni07b+AW4jpa2nzooWysK3kjEdw=; b=qzZhM rdWxwS0gej2qdnJytwPiB25YIUeLFG0IGyUHnxqTQUiBqRZSVJJhm8NllEZO392M bznKdQ+Sar8LeR3MpG7dgCjMFiZqT9QOFKL5fta3bw8LauGkT1itXaYl+8x300MJ fL4Oa6mRF1IdSx97Yp9BAdWrs/UjW0EPJR/hBo= Received: (qmail 92403 invoked by alias); 19 Oct 2017 21:00:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 91041 invoked by uid 89); 19 Oct 2017 21:00:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f194.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=vcLy6mTbmx3qTJFjc/XbTmoN3uvrsvc2sIYM9GajkvE=; b=cdbn5YKoCvK9uMXtRiLDO8vF7u8fNO6151b4J+u6xXj7v+xx/fImtc9p7Pczw9W3gB WoCilnAdtPsMhUXvM3QUIHKt5AkfCJ64xJTyHFmHHC3Rf/LCzLhX7HILeIUuhOsgL+uI X/hZHst5rdp5RXff4/z5h/EbXGzc7lYg7W6npFaQSmFgjrkwG6zJY208kAVJMlvMqjJL PjEcHsOuvlkDonVPW8tZn09BGkdRj5aP9d8WI1JRsWrY8dQIOH2sR0Hxmdp5bgxy7poW AfDAVO4yBTShZNIU8j0QfPFZi6GTp2CR2okO+sIQddeHAW9L+9lnFAu9YWolO8JjpZNL qvjg== X-Gm-Message-State: AMCzsaUSTzcv2F3rgzEhY50ldonv5vL2KPluYW88fmN2WkPQs7Mu8/qY 5tfNPjQkcFrRgUsxMVYqKKiQl9QW2pA= X-Google-Smtp-Source: ABhQp+Q6dks+kDm7qjt+HTSOgKrNHdlC/CocQNo1FAqlWYxRzAjK8zR/NF7rF++Ae+cJWrPrHyLQyg== X-Received: by 10.200.25.78 with SMTP id g14mr4052467qtk.225.1508446819031; Thu, 19 Oct 2017 14:00:19 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert Date: Thu, 19 Oct 2017 19:00:06 -0200 Message-Id: <1508446807-21704-2-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1508446807-21704-1-git-send-email-adhemerval.zanella@linaro.org> References: <1508446807-21704-1-git-send-email-adhemerval.zanella@linaro.org> Instead of rely on runtime check to assure correct pthread types size a better strategy would use _Static_assert to trigger an error on build time (and thus allowing to check to potentially ABI breakage on cross-compiling make check). Checked on x86_64-linux-gnu and with a build check for all affected ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf, hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu, microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu, mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu, s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu, sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32, tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32). * nptl/tst-typesizes.c: Make sizes check _Static_asserts at built time. --- ChangeLog | 3 ++ nptl/tst-typesizes.c | 77 +++++++++++++--------------------------------------- 2 files changed, 22 insertions(+), 58 deletions(-) -- 2.7.4 diff --git a/nptl/tst-typesizes.c b/nptl/tst-typesizes.c index 78ed773..3355614 100644 --- a/nptl/tst-typesizes.c +++ b/nptl/tst-typesizes.c @@ -20,56 +20,26 @@ #include #include -static const struct -{ - const char *name; - size_t expected; - size_t is; -} types[] = - { -#define T(t, c) \ - { #t, c, sizeof (t) } - T (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T), - T (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T), - T (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T), - T (pthread_cond_t, __SIZEOF_PTHREAD_COND_T), - T (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T), - T (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T), - T (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T), - T (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T), - T (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T) - }; - static int do_test (void) { - int result = 0; - -#define TEST_TYPE(name) \ - printf ("%s: ", #name); \ - if (sizeof (name) != sizeof (((name *) 0)->__size)) \ - { \ - printf ("expected %zu, is %zu\n", \ - sizeof (((name *) 0)->__size), sizeof (name)); \ - result = 1; \ - } \ - else \ - puts ("OK") - - TEST_TYPE (pthread_mutex_t); - TEST_TYPE (pthread_cond_t); - TEST_TYPE (pthread_rwlock_t); - -#define TEST_TYPE2(name, internal) \ - printf ("%s: ", #name); \ - if (sizeof (((name *) 0)->__size) < sizeof (internal)) \ - { \ - printf ("expected %zu, is %zu\n", \ - sizeof (((name *) 0)->__size), sizeof (internal)); \ - result = 1; \ - } \ - else \ - puts ("OK") +#define TEST_TYPE(__type, __size) \ + _Static_assert (sizeof (__type) == __size, \ + "sizeof (" #__type ") != " #__size) + + TEST_TYPE (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T); + TEST_TYPE (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T); + TEST_TYPE (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T); + TEST_TYPE (pthread_cond_t, __SIZEOF_PTHREAD_COND_T); + TEST_TYPE (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T); + TEST_TYPE (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T); + TEST_TYPE (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T); + TEST_TYPE (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T); + TEST_TYPE (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T); + +#define TEST_TYPE2(__type, __internal) \ + _Static_assert (sizeof ((__type *) 0)->__size >= sizeof (__internal), \ + "sizeof (" #__type ".__size) > sizeof (" #__internal ")") TEST_TYPE2 (pthread_attr_t, struct pthread_attr); TEST_TYPE2 (pthread_mutexattr_t, struct pthread_mutexattr); @@ -80,16 +50,7 @@ do_test (void) TEST_TYPE2 (sem_t, struct new_sem); TEST_TYPE2 (sem_t, struct old_sem); - for (size_t i = 0; i < sizeof (types) / sizeof (types[0]); ++i) - if (types[i].expected != types[i].is) - { - printf ("%s: expected %zu, is %zu\n", - types[i].name, types[i].expected, types[i].is); - result = 1; - } - - return result; + return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include