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: 1134847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-103871-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="ELJuWUhS"; dkim-atps=neutral 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 45sfcr4gY3z9s7T for ; Mon, 22 Jul 2019 21:33:32 +1000 (AEST) 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:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=xRL cR1si8OC9orqA06ldU9PTLXNjCNUvbEFQtIpKuwiG/aBpHjspMuWTq7NmdcaoGRZ qMJsA34Ip29CA3v1vMzArP67U7Z8MgsmeTlPnb8nFbfmEh3d219FqWsDLFKMULsw JJlx3tpM12JgJPG6fSOOuBP6dLHGs9j862g6S59k= 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:mime-version :content-type:content-transfer-encoding; s=default; bh=DlXmLB3ae x8lzEOwUq5ketLD5i4=; b=ELJuWUhSx4W0O97XMwpRnL6QdQ6uUIbpY2duhsLUM Tx1dlXntbGoJ6Y7Isb236mqzgSbJ8Bs+0CJcOorfpv5/YXEL8githQAxUWsrD9u/ Vz1j71BqCWSvBMpojaP4qx3u51ng1cK8AWpkM49R3hXbZ7jWD+LpdaEEakgRCJny FA= 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