From patchwork Mon Jul 22 11:33:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 33767 Received: (qmail 75332 invoked by alias); 22 Jul 2019 11:33:27 -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 75321 invoked by uid 89); 22 Jul 2019 11:33:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=marks X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Add compiler barrier in nptl/tst-pthread-getattr Date: Mon, 22 Jul 2019 13:33:22 +0200 Message-ID: <87blxms3r1.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Recent GCC versions warn about the attempt to return the address of a local variable: tst-pthread-getattr.c: In function ‘allocate_and_test’: tst-pthread-getattr.c:54:10: error: function returns address of local variable [-Werror=return-local-addr] 54 | return mem; | ^~~ In file included from ../include/alloca.h:3, from tst-pthread-getattr.c:26: ../stdlib/alloca.h:35:23: note: declared here 35 | # define alloca(size) __builtin_alloca (size) | ^~~~~~~~~~~~~~~~~~~~~~~ tst-pthread-getattr.c:51:9: note: in expansion of macro ‘alloca’ 51 | mem = alloca ((size_t) (mem - target)); | ^~~~~~ 2019-07-22 Florian Weimer * nptl/tst-pthread-getattr.c (compiler_barrier): New function. (allocate_and_test): Use it. diff --git a/nptl/tst-pthread-getattr.c b/nptl/tst-pthread-getattr.c index a954778767..a11a25437d 100644 --- a/nptl/tst-pthread-getattr.c +++ b/nptl/tst-pthread-getattr.c @@ -41,6 +41,15 @@ static size_t pagesize; +/* The weak attribute marks this function as interposable, so the + compiler cannot assume that the pointer remains unchanged. */ +__attribute__ ((noinline, noclone, weak)) +volatile char * +compiler_barrier (volatile char *ptr) +{ + return ptr; +} + /* Check if the page in which TARGET lies is accessible. This will segfault if it fails. */ static volatile char * @@ -51,7 +60,10 @@ allocate_and_test (char *target) mem = alloca ((size_t) (mem - target)); *mem = 42; - return mem; + + /* Insert the compiler barrier to hide the fact that mem is + stack-allocated. The address is only used in a diagnostic. */ + return compiler_barrier (mem); } static int