From patchwork Tue Dec 4 03:23:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1007416 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=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-491570-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="m41dAvAH"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eQFyH1s/"; 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 4386ds5pMZz9s3C for ; Tue, 4 Dec 2018 14:23:44 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=uJuRIT6fBOiwyrsqoXUXfeX9cllhsibIv0rtRsrShhdt4vZ2w+ oecfOeY/iNYPHQNAC45CO1rX7PWucPy8zMBTuB2tXgaeeL8OOYbmb7Pv7YbbfC2K C//PP4lRKKvqc65FQrCF1KoES7rGOsNTRvtWTwyBuHhmu/ekjnXUt/PL8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=WP02jZ8xiOpp2BipuScwBUyUJ2U=; b=m41dAvAH7dzs3I4REAqf xyPtpdfN1wkuMmgQ2Pe7vtcNFNq+0zR5vvznN+32XojJLF6mQal+vT8NhX6/A5P2 R5OPgJzz2kzlwmckTy7ef/RZKNDthVag8bxeVxkR4MC3U1g2mpYK6CF0JcMgfKhl friAqxXP7oPthWtjMD8eECc= Received: (qmail 116694 invoked by alias); 4 Dec 2018 03:23:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 116664 invoked by uid 89); 4 Dec 2018 03:23:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=translation, decrease X-HELO: mail-qk1-f179.google.com Received: from mail-qk1-f179.google.com (HELO mail-qk1-f179.google.com) (209.85.222.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Dec 2018 03:23:30 +0000 Received: by mail-qk1-f179.google.com with SMTP id w204so8780407qka.2 for ; Mon, 03 Dec 2018 19:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=iSaH+NyQv8JFEC7nOSTXLaHmwF9PwOemfr2svmndECc=; b=eQFyH1s/HLFnvRCq87UXgU1+a7F7wyxmkUQ648zjMuUmE90OmDMF9AHaF8zsfVrsi0 0JhnxHYj6ZRn3c5m31WFKcnUMy6yXtJcV15SnX0YvNtGyyrgN0wX5XqL4qMrqGT1kJua A+C6RYTmgLx4aL1PZRkdxTAq2DzxUKSDM8b5wpwzgLilgdpSGa693OIKngVR9c9mwjXM Ixybo5zquG9TCBxXjrNCQf41nxDAJXT6smxDlmXOkuy9lAHW4uqA9J9MZmKGgY0b7Uop PRlliRr8tRCGoMfquwTL5aeODy+/4py9OEc/lVCmpVipSgalQuQ1dAuvfmaSbE27dS0z JgxA== Received: from localhost.localdomain (97-118-99-160.hlrn.qwest.net. [97.118.99.160]) by smtp.gmail.com with ESMTPSA id j33sm8763310qte.38.2018.12.03.19.23.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 19:23:27 -0800 (PST) To: Jeff Law , Gcc Patch List From: Martin Sebor Subject: [doc PATCH] document when GCC ignores attribute aligned Message-ID: Date: Mon, 3 Dec 2018 20:23:25 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes Last week we agreed to clarify that attribute aligned on a function can decrease its alignment if it hasn't been previously declared with one. Attached is this change. Besides the above, I also mention that the attribute specifies the alignment of the first instruction of the function (in case that wasn't obvious) , and that it has no effect in the absence of a definition. I wrote some tests to convince myself this actually works as I expected. Where it does I add those tests to the testsuite via this patch. Where it doesn't I opened a bug (PR 88345). Martin gcc/ChangeLog: * doc/extend.texi (attribute aligned): Expand. gcc/testsuite/ChangeLog: * gcc.target/i386/attr-aligned-2.c: New test. * gcc.target/i386/falign-functions-3.c: New test. Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 266766) +++ gcc/doc/extend.texi (working copy) @@ -2386,16 +2386,20 @@ and may not be available on all targets. @itemx aligned (@var{alignment}) @cindex @code{aligned} function attribute The @code{aligned} attribute specifies a minimum alignment for -the function, measured in bytes. When specified, @var{alignment} must -be an integer constant power of 2. Specifying no @var{alignment} argument -implies the maximum alignment for the target, which is often, but by no -means always, 8 or 16 bytes. +the first instruction of the function, measured in bytes. When specified, +@var{alignment} must be an integer constant power of 2. Specifying no +@var{alignment} argument implies the ideal alignment for the target, +which is often, but by no means always, 8 or 16 bytes. The attribute +has no effect when a definition for the function is not provided in +the same translation unit. -You cannot use this attribute to decrease the alignment of a function, -only to increase it. However, when you explicitly specify a function -alignment this overrides the effect of the -@option{-falign-functions} (@pxref{Optimize Options}) option for this -function. +The attribute cannot be used to decrease the alignment of a function +previously declared with a more restrictive alignment; only to increase +it. Attempts to do otherwise are diagnosed. Some targets specify +a minimum default alignment for functions that is greater than 1. On +such targets, specifying a less restrictive alignment is silently ignored. +Using the attribute overrides the effect of the @option{-falign-functions} +(@pxref{Optimize Options}) option for this function. Note that the effectiveness of @code{aligned} attributes may be limited by inherent limitations in the system linker Index: gcc/testsuite/gcc.target/i386/attr-aligned-2.c =================================================================== --- gcc/testsuite/gcc.target/i386/attr-aligned-2.c (nonexistent) +++ gcc/testsuite/gcc.target/i386/attr-aligned-2.c (working copy) @@ -0,0 +1,28 @@ +/* Verify that valid alignment on either a function declaration + or a definition has the expected effect and overrides -Os. + { dg-do compile } + { dg-options "-Os" } */ + +#define ALIGN(n) __attribute__ ((aligned (n))) + +/* No alignment specified (to cause the subsequent instruction + to be at an odd boundary due to -Os). */ +void f (void) { } + +void f4 (void); + +ALIGN (4) +void f4 (void) { } + +/* { dg-final { scan-assembler ".align 4\n\t.globl\tf4" } } */ + + +void g (void) { } + + +ALIGN (4) +void g4 (void); + +void g4 (void) { } + +/* { dg-final { scan-assembler ".align 4\n\t.globl\tg4" } } */ Index: gcc/testsuite/gcc.target/i386/falign-functions-3.c =================================================================== --- gcc/testsuite/gcc.target/i386/falign-functions-3.c (nonexistent) +++ gcc/testsuite/gcc.target/i386/falign-functions-3.c (working copy) @@ -0,0 +1,23 @@ +/* Verify that attribute aligned overrides the effect of -falign-functions. + (But see PR 88345 showing that -Os overrides -falign-functions.) + The test may need to be adjusted if/when GCC implements PR 88231. + { dg-do compile } + { dg-options "-O2 -falign-functions=32" } */ + +#define ALIGN(n) __attribute__ ((aligned (n))) + +ALIGN (4) +void f4 (void) { } + +/* { dg-final { scan-assembler ".align 4\n\t.globl\tf4" } } */ + + +void f32 (void) { } + +/* { dg-final { scan-assembler ".p2align 5\n\t.globl\tf32" } } */ + + +ALIGN (64) +void f64 (void) { } + +/* { dg-final { scan-assembler ".align 64\n\t.globl\tf64" } } */