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: 23715 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(-) 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