From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id E1EA63858437 for ; Thu, 18 Aug 2022 13:02:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1EA63858437 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27IBvSt3027761 for ; Thu, 18 Aug 2022 13:02:30 GMT Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j1n0sg51w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 18 Aug 2022 13:02:30 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27IAXrS5020868 for ; Thu, 18 Aug 2022 13:02:29 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j0c48sey2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 18 Aug 2022 13:02:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bZ2uHxAF+NP/U9kWA32JBmh/NDAEsF6kbbKeUO40q7tm+/cS4QkxDdQhdXa8zYyBQlhAt0EuymMJ43eYvhOi0ni+NphFirdYl3uzjr8/EK0NN4NYM5PM41MTeCYb2MIn784nTGyXIXVoMRpXb6AzS7oN2T7ajNzTlBzodZ3slN8GG8nyMWtzdfQwb7gT+gaQaWPTXDmTzufL3AIJZ+qPTEXjW26HtXf3RjUo009PqOka7fK58f5PXu3z2+MntgyEzklDKntOHKzuR6UXX61DkPkInVHpB4xtGWwNavm1KKo5/UB68hKLyIYfama0LVfBc4dxNziJE3flQUl/19pmMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=31rXOTj8WItw4QlpO6cRD5ci9Bo6wrgblPtJnsBUNK0=; b=eGoyORZBXcSaPdOs0GzznsEpkff8et5qJCXLzHqNHyOPrnK7V/PMh6XgmBsBhhwjFXhq/Ns/0Jh30eBMojthEukq15Tnmrq/RpgoMgSNbHj1dZlR/uZXX2nvskIUBJKqvox292HTyLdrHa+upH/EPLhb0q3L5SXsUSX/6BjwKyjSyV6o2u3aWRp47kJ31ef+hjgMCQzfrdslmXpXjj9q/2PjV/9+gvTyzIlpbMju4rBY4gexvhfu0d6WHl8waZG/+IpE1cyLMXhPwTj9y76UIoqqN3v9+lmQKNdUu2dxi4/OG/3oKpMk9CFqbPIJ5YkUOOmglFVoBehGRoE4ex1sWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by CH0PR10MB4905.namprd10.prod.outlook.com (2603:10b6:610:ca::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Thu, 18 Aug 2022 13:02:27 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::b5ee:262a:b151:2fdd]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::b5ee:262a:b151:2fdd%4]) with mapi id 15.20.5525.010; Thu, 18 Aug 2022 13:02:27 +0000 From: "Jose E. Marchesi" To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH V2] place `const volatile' objects in read-only sections References: <87zggiudcr.fsf@oracle.com> Date: Thu, 18 Aug 2022 15:02:22 +0200 In-Reply-To: <87zggiudcr.fsf@oracle.com> (Jose E. Marchesi's message of "Fri, 05 Aug 2022 13:41:24 +0200") Message-ID: <875yipd7s1.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Content-Type: text/plain X-ClientProxiedBy: AS4P192CA0009.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:5da::16) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d5feec10-de35-4765-b9b2-08da8119e6c4 X-MS-TrafficTypeDiagnostic: CH0PR10MB4905:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7Yj2N8iYshSMA626Od6HSXQjAydxHmKmWmOCyzGNhMAzs1QNnjPMu+H6QjTsOg1FDE1qJiUgTFCEm8hH0Y9C07bGWXg481xMqx093BrK5AF+I4s6LroXNwSoNi53enk92kb4xShl0eLH39Jgk8/ozHlb31cSqCYm/pvdiN3kwUinzw7V2kcPQQYfMA8IqPPdlqT9Es6Qq9RU2Nm0sOGhPeWySvGJLWVtKIAYGMC6wPtSJdFnN056aPwyHrXV1LrqkV/ofxkKUFYicV9G44uTcASYc5IUH9dWlMfKZWICYcNi/OOb9H7hiA+jri1ijDcejy9uhokTnmRY546dUftV4rOYF5zW00njWNeu7zPZWWSsEru+OHFPQNZ9+TTYLO/AiwXiM9pCxpctHzZ26IfUfZzjQ8uEQcJty4fC9LVUJ4+i38zSSqTU1XgbkmjaZLvnDCM1rxk7SWR6TKclFRMmHj8LUBCRga7NFjodOKNS0fGfs5y8ae+/0wbDlgd8zkvobhzFQgd2q6XMMGdlHcdDCsI+ntcs6pkmeipshiS33gLpiFjT29DV2PtloD/6/FOLrfWNqFt77We6SkuM173tEc95lB+GKsPZaNHX5QWEitJc0aM+l/6tT8KOqJ/0Yd5g14LIipQO0ZKr6mGpt00oHrDRhPM/U9lNgz3QTss9pSMTSOVHwUW7wekq5GztOShB1TVj71FsCsN/nxCPm+W9oVkcoJpW/uDVFvucAvp5qwQL1UxQJtZAfckcxcOxEUuvPPF4e1A9HWSbSvMXSvErmcg2XHmXW9aC4fpkGwpFtzdpoXXTz9R3zWqyikFqaimv X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2888.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(136003)(346002)(376002)(39860400002)(396003)(41300700001)(6666004)(2906002)(966005)(6486002)(66476007)(66556008)(8676002)(66946007)(8936002)(5660300002)(86362001)(186003)(478600001)(83380400001)(2616005)(6512007)(26005)(6506007)(38100700002)(316002)(84970400001)(36756003)(6916009)(81973001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wEPJycYQfOdhz68uMvkfttFMsVHuXr8yHSnZPHSjrsIe5SGItvrCudOpYFbE?= =?us-ascii?Q?Fiqzt5qL8xFqYMm0Dw/wJihzyi59tEO6kCGeOJE59pNrlNvNFHIaRZ75jF0s?= =?us-ascii?Q?2ELECFHVesoZgRoVXz1zFTtiFQB+mAHuxx54PKABj/9Bt+YFrdZziYLBPjTs?= =?us-ascii?Q?zMFRkrty/cM9D5m49GU9FBSOLkE3juXHl5jxUF/9nzE8uF28rvcywoCP+B4I?= =?us-ascii?Q?/brkz1Px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Vfr?= =?us-ascii?Q?+F9VNPyQim2FAcf+QAJQZVCLPnAfWS/Nmk9YSl3LXBOD5W1102mY3bOO17LA?= =?us-ascii?Q?ivYoM92foXaV2tv++Pjq16jbdE/cU+p6Vhq45nO6LfApo+k6DoGEhUjeUVSr?= =?us-ascii?Q?3lxwC0Tzp/l20wpl1JcGD0ig+SMh2E9EerNnWKJQ7t7zA9Afxhu1ug/uSlhw?= =?us-ascii?Q?aueHUzbzPVu9dodcLkdJ7i9kOLFeTxAk5nVflpA48TvI05J5TA//oFc/OEHU?= =?us-ascii?Q?FDm1CFUkS8GrSncmVZtPGZYWNl0vIFRvz8WDB7M5Jzl+bNDbWTvNAvhtYw53?= =?us-ascii?Q?m+0UK/GWbwbWYBtgpoaibmK5aZEQHGPFvLykEPcT7midM3f1yfm893z37Gww?= =?us-ascii?Q?vZpoVGUjpiIB1nxbzJarCDf6z3oPWT5BWw9ehB9W6emqznAPgk17GamKlaeA?= =?us-ascii?Q?gps/26JbKd+pSa9Q+dAuS+p9PT4DvXFwzve28knA7EBZEjHWCjlrw3bEL3M5?= =?us-ascii?Q?RA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: WevqE11+zVT7sfv2B0c0RQNA1o/xQQQxbClgkJEFQfWHE3P9b765TE3NQK0JetrJnrwb65X1I428lHGThtGS52md3Svc+vA/wHYOXAiLZ9hefL1qp4/NqmGf4r67efe00001dzVe69JBP1C8D4QenMAROUc3w9RIYcxF+81gADsk6kuBjwD0L0AdSxUS5aW3gXekbre78Cy6wJLggQC/kWCykJr7wBNf9i3RCpvvlQ4qoLNQd30GwGGgPEjNReagG63OFtkvqnXGwmNB37YsOyQ9f5RrdRmLB+KAXw38gkBA1cheJ3vBSQJzlBxMVqnl/T3or7kSU9NXv5+UmzCplzEKXyp1th0YeDrQm78rf4PjICLTRJajd9lPReWEjPzZBE1oh8qXmcYrPtB8pAUMeDpi7W1J0C7jfpyHRC+dNHVwzFpo58iMUvfxKHv3ZnwOOK4X9ckGsN4vHXwC4mp2yFW2rYFxeGkZRQ4+FSqaaMPQQHxcPGnRn4IblId3zfFfLlrAiho4U7rs3XHgAEY2L2/XYcvtbMvrNj++QRfZUEsoVZbg8VR8sDUckWFku8661RZoe+pFKzYVaVoJfqugG3M7mJMTEm9xSBZAeks9/KwvUcVcJFZRlfzQIQ7qpdTBAPJaxTk6h/a6xru+Bpv9lOVzuVba/DvuH/MLuh695JbpDlqt247WDTIpCadn2ytzgtxK3PE4JQ/Mae+Exq6G6A== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5feec10-de35-4765-b9b2-08da8119e6c4 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2022 13:02:27.3726 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: chvxI6Qh4kMWOq3rOpeL8VCn/Ab8R2lhnCtViOBWNBdEyytUMcQeZHs7tJMF9/4BEo9YSC+4Y4iur8Tsj8JI3rYUFs0ebIVVXfb/WHzBEmA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4905 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-18_12,2022-08-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208180044 X-Proofpoint-ORIG-GUID: 3oPJY_SIalSuxXeFIeBaoZq_frQ9_g1A X-Proofpoint-GUID: 3oPJY_SIalSuxXeFIeBaoZq_frQ9_g1A X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2022 13:02:32 -0000 ping > [Changes from V1: > - Added a test.] > > It is common for C BPF programs to use variables that are implicitly > set by the BPF loader and run-time. It is also necessary for these > variables to be stored in read-only storage so the BPF verifier > recognizes them as such. This leads to declarations using both > `const' and `volatile' qualifiers, like this: > > const volatile unsigned char is_allow_list = 0; > > Where `volatile' is used to avoid the compiler to optimize out the > variable, or turn it into a constant, and `const' to make sure it is > placed in .rodata. > > Now, it happens that: > > - GCC places `const volatile' objects in the .data section, under the > assumption that `volatile' somehow voids the `const'. > > - LLVM places `const volatile' objects in .rodata, under the > assumption that `volatile' is orthogonal to `const'. > > So there is a divergence, that has practical consequences: it makes > BPF programs compiled with GCC to not work properly. > > When looking into this, I found this bugzilla: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25521 > "change semantics of const volatile variables" > > which was filed back in 2005, long ago. This report was already > asking to put `const volatile' objects in .rodata, questioning the > current behavior. > > While discussing this in the #gcc IRC channel I was pointed out to the > following excerpt from the C18 spec: > > 6.7.3 Type qualifiers / 5 The properties associated with qualified > types are meaningful only for expressions that are > lval-values [note 135] > > 135) The implementation may place a const object that is not > volatile in a read-only region of storage. Moreover, the > implementation need not allocate storage for such an object if > its $ address is never used. > > This footnote may be interpreted as if const objects that are volatile > shouldn't be put in read-only storage. Even if I personally was not > very convinced of that interpretation (see my earlier comment in BZ > 25521) I filed the following issue in the LLVM tracker in order to > discuss the matter: > > https://github.com/llvm/llvm-project/issues/56468 > > As you can see, Aaron Ballman, one of the LLVM hackers, asked the WG14 > reflectors about this. He reported that the reflectors don't think > footnote 135 has any normative value. > > So, not having a normative mandate on either direction, there are two > options: > > a) To change GCC to place `const volatile' objects in .rodata instead > of .data. > > b) To change LLVM to place `const volatile' objects in .data instead > of .rodata. > > Considering that: > > - One target (bpf-unknown-none) breaks with the current GCC behavior. > > - No target/platform relies on the GCC behavior, that we know. > > - Changing the LLVM behavior at this point would be very severely > traumatic for the BPF people and their users. > > I think the right thing to do at this point is a). > Therefore this patch. > > Regtested in x86_64-linux-gnu and bpf-unknown-none. > No regressions observed. > > gcc/ChangeLog: > > PR middle-end/25521 > * varasm.cc (categorize_decl_for_section): Place `const volatile' > objects in read-only sections. > (default_select_section): Likewise. > > gcc/testsuite/ChangeLog: > > PR middle-end/25521 > * lib/target-supports.exp (check_effective_target_elf): Define. > * gcc.dg/pr25521.c: New test. > --- > gcc/testsuite/gcc.dg/pr25521.c | 10 ++++++++++ > gcc/testsuite/lib/target-supports.exp | 10 ++++++++++ > gcc/varasm.cc | 3 --- > 3 files changed, 20 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr25521.c > > diff --git a/gcc/testsuite/gcc.dg/pr25521.c b/gcc/testsuite/gcc.dg/pr25521.c > new file mode 100644 > index 00000000000..74fe2ae6626 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr25521.c > @@ -0,0 +1,10 @@ > +/* PR middle-end/25521 - place `const volatile' objects in read-only > + sections. > + > + { dg-require-effective-target elf } > + { dg-do compile } */ > + > +const volatile int foo = 30; > + > + > +/* { dg-final { scan-assembler "\\.rodata" } } */ > diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp > index 04a2a8e8659..c663d59264b 100644 > --- a/gcc/testsuite/lib/target-supports.exp > +++ b/gcc/testsuite/lib/target-supports.exp > @@ -483,6 +483,16 @@ proc check_effective_target_alias { } { > } > } > > +# Returns 1 if the target uses the ELF object format, 0 otherwise. > + > +proc check_effective_target_elf { } { > + if { [gcc_target_object_format] == "elf" } { > + return 1; > + } else { > + return 0; > + } > +} > + > # Returns 1 if the target toolchain supports ifunc, 0 otherwise. > > proc check_ifunc_available { } { > diff --git a/gcc/varasm.cc b/gcc/varasm.cc > index 4db8506b106..7864db11faf 100644 > --- a/gcc/varasm.cc > +++ b/gcc/varasm.cc > @@ -6971,7 +6971,6 @@ default_select_section (tree decl, int reloc, > { > if (! ((flag_pic && reloc) > || !TREE_READONLY (decl) > - || TREE_SIDE_EFFECTS (decl) > || !TREE_CONSTANT (decl))) > return readonly_data_section; > } > @@ -7005,7 +7004,6 @@ categorize_decl_for_section (const_tree decl, int reloc) > if (bss_initializer_p (decl)) > ret = SECCAT_BSS; > else if (! TREE_READONLY (decl) > - || TREE_SIDE_EFFECTS (decl) > || (DECL_INITIAL (decl) > && ! TREE_CONSTANT (DECL_INITIAL (decl)))) > { > @@ -7046,7 +7044,6 @@ categorize_decl_for_section (const_tree decl, int reloc) > else if (TREE_CODE (decl) == CONSTRUCTOR) > { > if ((reloc & targetm.asm_out.reloc_rw_mask ()) > - || TREE_SIDE_EFFECTS (decl) > || ! TREE_CONSTANT (decl)) > ret = SECCAT_DATA; > else