From patchwork Mon Oct 16 20:44:12 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: 115984 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4101952qgn; Mon, 16 Oct 2017 13:44:35 -0700 (PDT) X-Received: by 10.99.109.14 with SMTP id i14mr9353354pgc.355.1508186675050; Mon, 16 Oct 2017 13:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508186675; cv=none; d=google.com; s=arc-20160816; b=vXjiYbZZ8nuHdLPP0uMv+FoAyYOXAtBV5rCDk6tz0AW4Ll3gfZ+rwSM7ZzbH14C7l2 jnqlOKZhE6XqC7AnH8KWhPN0GHxZDDr7WcglP0ZAEPlS89jScYQ4ajfEFAB5jRrIPEBV UQEHw9r5I3b8PKz8tGkQD6Bzb5nbjElG6aH/M5ICqfc+NHwloBEjDdEEWQ+1U70MQsSV SV6ydOayHf7vum/rwRHIv/ryejGKe7nAeelzFNUO9dGhTNqo9+x98CmpIVz7S85vWuV3 SqfFD1u11rpESAiOLbtqWUi+7cYmHU/j/OGyBr7pTQrdAvLOABBBnmR0E0ykLmYF1ntN Xh8g== 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=Ne0C/hkwDnLtf0CaF+R1XE3T8x6LHYGjJpidTjpcjkx5dQgyDE4KptD0im7U3UgKYc wa6usp4Bhu6RDg34LICEpJk38pbBKmZSybrpmuAsDxGN20xNdl/FzJ+i5iGmxmGrKEmS ZSoXerBbMF6xaxG9OVIbn6Eh2IL/CMTl0bJZV3HfZCi47mrDBAimNtFiudfiitU3IzQY m7KGpXAk8oc7ZTJiO9Gqcg8i/5H7xJ6ZgeDwspkQBKbchlcGQ1JgBnVIJoMWWMuVsUlj wYzJ/hadGlKdx4ZmObtUhzkJu1++6wWSiQApBBUENaDBUYPEmKioNUk10KF22YLMRr8w 3Kbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=aPy5uRyN; spf=pass (google.com: domain of libc-alpha-return-85909-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-85909-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 f3si4829731pfd.366.2017.10.16.13.44.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Oct 2017 13:44:35 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-85909-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=aPy5uRyN; spf=pass (google.com: domain of libc-alpha-return-85909-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-85909-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=m74MYwh0BiF9Kyf+rlfuHhwxJI1aG7U E/bLqIwfuvqn+q6ujNRksvws/OdaJT1q36GFNHPJquYwDbpv/xGc0nGAXIZzFGq/ XzxU0CIJzpYAoBURcdFzIF9efyUbbnnNXEnAVchd2Sxnj7LaNbtfG4IVhEcwcNOY CooUlQyEP78I= 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=aPy5u RyNzCNrqEb5Cfhdg/6kb1PpW4X/Dj2ty9fW4bHn88lPo33T4IIi/xogU09lL9pXA ACWuNpD77UTfWAytGfDzwqzahtBqt7kaVH2lOxEyx2m74ma6Xf7+zA3UdKbcsDGG 6quakEvmVJqnKVwUI6sG/RHycArrd8jcTxOruk= Received: (qmail 129273 invoked by alias); 16 Oct 2017 20:44:25 -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 129252 invoked by uid 89); 16 Oct 2017 20:44:24 -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-qk0-f180.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=WyiDYO9PzD4OQaJ/XHzAzwi6MMQl3q/Srz6zx48a57mEeM5jQJ2o+3hoUiznJgaqZ1 r4CP0ePorRYgdkVe5GXUGQLeIiA1KaNUMTDcDE1Hh4Sp0/NoARc38vgSXyDDlS9oDYDA zKomghZKz0QX7iK/Ynrlb62VSlPSDuTftoY2rInSpodOad+Cncdg23HEUt76Fzc3JFsr xcwe1MvU6mTg0Rx1wmJcB2/M1nd16IT8hGS7EiyOX7q1Z6EkCpyz07QJRo4amQrlciNF XT0MOlwFYM8B9O/hBxLCf9J6PQkUJUbEn5fHJJFBqlDH/+X7SryQcw2/FvsP1nj5kZDN WYAw== X-Gm-Message-State: AMCzsaUrv0LzsVBAvuNo+I0F6UucXNzKQSd7kg3DW3VpZP+KLHVxK64z tYREDnuR2BtMqfGTPRyxtlUFf4mhoMU= X-Google-Smtp-Source: ABhQp+SE05shdOE5Zgy0GgG37ZYY2ykV2WMkNv7FvNWf8unnqWfYL4C2bqO2vFnksE//Aq7Cnr9DjQ== X-Received: by 10.55.15.42 with SMTP id z42mr15416673qkg.181.1508186661666; Mon, 16 Oct 2017 13:44:21 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert Date: Mon, 16 Oct 2017 18:44:12 -0200 Message-Id: <1508186653-24430-2-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1508186653-24430-1-git-send-email-adhemerval.zanella@linaro.org> References: <1508186653-24430-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