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 156C1383581C for ; Tue, 24 May 2022 15:53:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 156C1383581C Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFShs4001538; Tue, 24 May 2022 15:53:26 GMT Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6pgbpscy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:53:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFkYwW038042; Tue, 24 May 2022 15:53:24 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2105.outbound.protection.outlook.com [104.47.58.105]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3g6ph2s7ex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:53:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WP3U56OiVgukMXl1+04+cL/BhxVjU/MTzZmVDp1/VOy802vCkptxeoGq+Gcz3Ov8lpqBWNipT/wws6vRERonE0qlq2/K3Jx7hjkRic0Pnea3wd8mCy3xmDErX6rQhQHQWMNle1t2BXBT4HdUJSGz5Jbk/cABbixSdFYY7i+HjNsmUarM9tOAFN2wrVWWnMCCeWhlxBEK6yqxFc914B+UNhbXJF5SYC+igz4MamKUaYNPKDBi8i6LYdPPRvfuKRw64ZBxGPAo4jiIzAshJ7a3ZzpPmCjeZqIs10Wdc3KdXYSAj6LWdZApX719W1iue/pDRrpa5l/hfkWPK6Npkp6isw== 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=oEf6j++6uoCTPkZ97oo1MbfAaENyJwzWdX+cMir4XMU=; b=AFhhYjbNR/Q9tD7Bl2iZudoCgu4IvPlbPAOn5u2yL/YodSpvtXyGrtaTsGspBDEOR98e9Lb6otfy6tKBz4QaSq5gggqkikgiYYVcTzrjTC6bneg69Ns+IYYeB1bADB2iTVv3WY7ssUZX5GX+kO8Bpm6N+3UVuNBFwI9YAuWeosEqiMbbydV7mRXKGQ2t6C1nViinHXXcRLY//niXhpsBZdl0i/TAxH1DeX6aZlFO8RJhZ4KXkwLKUXgt/z+Hcs6SpLfbscT9bUb5khgV0YM3mDT3Tmc6EaxsjS6aMOPeLlk4BolyQOQgxJSlKzZNGDmM5lSabkgcgIaOQMAqhRxhqA== 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 MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by BL0PR10MB2882.namprd10.prod.outlook.com (2603:10b6:208:33::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.15; Tue, 24 May 2022 15:53:21 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::4939:15e0:57cb:87fb]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::4939:15e0:57cb:87fb%5]) with mapi id 15.20.5273.023; Tue, 24 May 2022 15:53:21 +0000 Message-ID: <0f4fcf9d-c0ab-6221-063f-67c1e6808fe1@oracle.com> Date: Tue, 24 May 2022 08:53:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [ping2][PATCH 0/8][RFC] Support BTF decl_tag and type_tag annotations Content-Language: en-US To: Yonghong Song , "Jose E. Marchesi" Cc: Joseph Myers , Yonghong Song via Gcc-patches References: <20220401194216.16469-1-david.faust@oracle.com> <7419ae42-55c8-87d6-2a19-74cebff51fb4@oracle.com> <7125844e-f538-faca-1cdf-5322492c00d9@fb.com> <54eb0e21-cbca-dbf5-88f1-d8febd091be8@fb.com> <9ec418b0-b002-085f-fc89-5a05fc3cd3c4@fb.com> <87h75fxk80.fsf@oracle.com> From: David Faust In-Reply-To: <87h75fxk80.fsf@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR03CA0196.namprd03.prod.outlook.com (2603:10b6:a03:2ef::21) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5e467a04-b9b2-48b5-ff98-08da3d9d8739 X-MS-TrafficTypeDiagnostic: BL0PR10MB2882:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M8qwgDKMmNqjk2DfuiINWIqWJOOj5TZCEMVkiFCyX/HPp/rsCSn+zWORk7+MNxJOohtgGv/tEQAl4xgyF2RH6lBkEL7YnCZXW+jf5AFludw9nZnwhUh7v5PhJXn9mEtOj5SgPH42/jTyvuFAVe5+Lc3Y9/Pi2vAwvu0nFtL1Xzl81qmvSmkSk0Go4aKHdoC1z66B8d79U0QFEeZc3LVHh1N/jqjrDoIvb2Rrad2/waLZHfzw+vyAwi71fcgylkANmob88b1XkqgVbisJrcfbm7hiIZ2/tftSIC/ZoPgjU2c00FGK2KYY+i0wcnVQ73slux9o5hBvVvoKwiV150d3gGGzWmkuBDfOo6bZ0gDs+f4jcwedYCtUgmT1KcweZlF1FaAEbTi9DiyZ11JV16tf/7mTc5JuyTPUip85Obj+9QeccB5mWn5B28SgZPleW25I8WFIEoGyG1lK43RHtwM65+Am663I6fB5c1TJc5HM4orlzYo9wxjLJEdlUaGztoPvKk0uoCGivfaoYXR5PRsaZZI0ihYFlzrCCyMrI8mOwosnDZ4mrY9ne05tDec/gl/RMy+xCgXMtGuXksr0p+QOVIPNX2iatYq/lkcQi9XhE4gOApZ67FoUdaV7T3ZgEqZVfz28ZHLk62eX+dQp+2tEwJ82QGw3RFAjmegHHTtT/Q9YEcOqH3rJmhnBo0IzSp1WBVjbWRty6VaypnIylYJfGk1VxPdj7zH1V9eHALPAU/3wlYNfUpYCMHorZtsC9GSo7Jm551N+grHiLGEKkqjvu73kSoqGELVPAmjjA2oeUWiY3dJnK2IN1S+dFMPWUSFk X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB3213.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(186003)(53546011)(83380400001)(5660300002)(44832011)(30864003)(36756003)(2616005)(8936002)(38100700002)(6506007)(6512007)(110136005)(54906003)(66556008)(8676002)(66476007)(4326008)(508600001)(6666004)(66946007)(6636002)(2906002)(966005)(6486002)(86362001)(316002)(31696002)(31686004)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZHU1WGg5SjlpQmpmWDQrY0psNjNRYlJmcTliK2txeXliUFNRbXNTaWFpVksw?= =?utf-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cjZrRThTM0FpTmZkb25TVjhDUzlLdGI1VDRld2c0a2VmMVd1N0p2?= =?utf-8?B?SzNaRlVuTVYwR1JhWDFldUhzUlVwTVRaOWQ0Sk4yY1pnQ0NwWkFNeGJUMFlQ?= =?utf-8?B?c3BMOFFrOEJDMnkwTktxczVIa3ZTQmFkQUgyZWFSbzBrZzN0M2tqTzUyMzlR?= =?utf-8?B?ck9PNFBDWEVTSGRXelh3bGpwZ1hQbzN0aFEvVzRFWWgyaFZrbnVlMUtNRzJQ?= =?utf-8?B?WFhDUDlQV0pOdjd5bDNhVkMvUjJmK1luS2FwY3hYcStRSkVFU29HNzZGMWkz?= =?utf-8?B?RU1GbmxJblRkMFBxOHdkem4wVDlEYjBpY3dZaGVxNjhxb0gyaGFzbHQxSHdI?= =?utf-8?B?K1M2M0lIb1dWVEdrVU1tZUFCZDk2L3p2R0hIVkV5Q05DcXI3R3g4R2QwT3BS?= =?utf-8?B?Z2JuVzEwL1FIQzV2RVBMM0RoaUh6bkpHcGpmNGFwa3Vnb2lEeEd6M0NQSlNn?= =?utf-8?B?clpTd0E4OTloTThlNHdyMDRsRHh2KzFLelRPYkFyQ290d1JXVVJReVhiM2xp?= =?utf-8?Q?5n9a9mJNpgoBj5uFtgZMeIqCudFv+2M+Lyypd?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e467a04-b9b2-48b5-ff98-08da3d9d8739 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2022 15:53:21.6731 (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: 0K2hJY4WrwFZ38Hik3Ucjm67OFuej+UHVNS8TsSfnslQmUscXGuq82C7ZAqlHRH4Ptjv4gsdM6RN8sacf3vzmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB2882 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.874 definitions=2022-05-24_06:2022-05-23, 2022-05-24 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240081 X-Proofpoint-ORIG-GUID: guBQjXwnWEA5cQt70tV-61NpUx9Wncya X-Proofpoint-GUID: guBQjXwnWEA5cQt70tV-61NpUx9Wncya X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, 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: Tue, 24 May 2022 15:53:34 -0000 On 5/24/22 04:07, Jose E. Marchesi wrote: > >> On 5/11/22 11:44 AM, David Faust wrote: >>> >>> On 5/10/22 22:05, Yonghong Song wrote: >>>> >>>> >>>> On 5/10/22 8:43 PM, Yonghong Song wrote: >>>>> >>>>> >>>>> On 5/6/22 2:18 PM, David Faust wrote: >>>>>> >>>>>> >>>>>> On 5/5/22 16:00, Yonghong Song wrote: >>>>>>> >>>>>>> >>>>>>> On 5/4/22 10:03 AM, David Faust wrote: >>>>>>>> >>>>>>>> >>>>>>>> On 5/3/22 15:32, Joseph Myers wrote: >>>>>>>>> On Mon, 2 May 2022, David Faust via Gcc-patches wrote: >>>>>>>>> >>>>>>>>>> Consider the following example: >>>>>>>>>> >>>>>>>>>>       #define __typetag1 __attribute__((btf_type_tag("tag1"))) >>>>>>>>>>       #define __typetag2 __attribute__((btf_type_tag("tag2"))) >>>>>>>>>>       #define __typetag3 __attribute__((btf_type_tag("tag3"))) >>>>>>>>>> >>>>>>>>>>       int __typetag1 * __typetag2 __typetag3 * g; >>>>>>>>>> >>>>>>>>>> The expected behavior is that 'g' is "a pointer with tags >>>>>>>>>> 'tag2' and >>>>>>>>>> 'tag3', >>>>>>>>>> to a pointer with tag 'tag1' to an int". i.e.: >>>>>>>>> >>>>>>>>> That's not a correct expectation for either GNU __attribute__ or >>>>>>>>> C2x [[]] >>>>>>>>> attribute syntax.  In either syntax, __typetag2 __typetag3 should >>>>>>>>> apply to >>>>>>>>> the type to which g points, not to g or its type, just as if >>>>>>>>> you had a >>>>>>>>> type qualifier there.  You'd need to put the attributes (or >>>>>>>>> qualifier) >>>>>>>>> after the *, not before, to make them apply to the pointer >>>>>>>>> type. See >>>>>>>>> "Attribute Syntax" in the GCC manual for how the syntax is >>>>>>>>> defined for >>>>>>>>> GNU >>>>>>>>> attributes and deduce in turn, for each subsequence of the tokens >>>>>>>>> matching >>>>>>>>> the syntax for some kind of declarator, what the type for "T D1" >>>>>>>>> would be >>>>>>>>> as defined there and in the C standard, as deduced from the type for >>>>>>>>> "T D" >>>>>>>>> for a sub-declarator D. >>>>>>>>>    >> But GCC's attribute parsing produces a variable 'g' >>>>>>>>> which is "a >>>>>>>> pointer with >>>>>>>>>> tag 'tag1' to a pointer with tags 'tag2' and 'tag3' to an >>>>>>>>>> int", i.e. >>>>>>>>> >>>>>>>>> In GNU syntax, __typetag1 applies to the declaration, whereas in C2x >>>>>>>>> syntax it applies to int.  Again, if you wanted it to apply to the >>>>>>>>> pointer >>>>>>>>> type it would need to go after the * not before. >>>>>>>>> >>>>>>>>> If you are concerned with the fine details of what construct an >>>>>>>>> attribute >>>>>>>>> appertains to, I recommend using C2x syntax not GNU syntax. >>>>>>>>> >>>>>>>> >>>>>>>> Joseph, thank you! This is very helpful. My understanding of >>>>>>>> the syntax >>>>>>>> was not correct. >>>>>>>> >>>>>>>> (Actually, I made a bad mistake in paraphrasing this example from the >>>>>>>> discussion of it in the series cover letter. But, the reason >>>>>>>> why it is >>>>>>>> incorrect is the same.) >>>>>>>> >>>>>>>> >>>>>>>> Yonghong, is the specific ordering an expectation in BPF programs or >>>>>>>> other users of the tags? >>>>>>> >>>>>>> This is probably a language writing issue. We are saying tags only >>>>>>> apply to pointer. We probably should say it only apply to pointee. >>>>>>> >>>>>>> $ cat t.c >>>>>>> int const *ptr; >>>>>>> >>>>>>> the llvm ir debuginfo: >>>>>>> >>>>>>> !5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64) >>>>>>> !6 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !7) >>>>>>> !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) >>>>>>> >>>>>>> We could replace 'const' with a tag like below: >>>>>>> >>>>>>> int __attribute__((btf_type_tag("tag"))) *ptr; >>>>>>> >>>>>>> !5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, >>>>>>> annotations: !7) >>>>>>> !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) >>>>>>> !7 = !{!8} >>>>>>> !8 = !{!"btf_type_tag", !"tag"} >>>>>>> >>>>>>> In the above IR, we generate annotations to pointer_type because >>>>>>> we didn't invent a new DI type for encode btf_type_tag. But it is >>>>>>> totally okay to have IR looks like >>>>>>> >>>>>>> !5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) >>>>>>> !11 = !DIBtfTypeTagType(..., baseType: !6, name: !"Tag") >>>>>>> !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) >>>>>>> >>>>>> OK, thanks. >>>>>> >>>>>> There is still the question of why the DWARF generated for this case >>>>>> that I have been concerned about: >>>>>> >>>>>>     int __typetag1 * __typetag2 __typetag3 * g; >>>>>> >>>>>> differs between GCC (with this series) and clang. After studying it, >>>>>> GCC is doing with the attributes exactly as is described in the >>>>>> Attribute Syntax portion of the GCC manual where the GNU syntax is >>>>>> described. I do not think there is any problem here. >>>>>> >>>>>> So the difference in DWARF suggests to me that clang is not handling >>>>>> the GNU attribute syntax in this particular case correctly, since it >>>>>> seems to be associating __typetag2 and __typetag3 to g's type rather >>>>>> than the type to which it points. >>>>>> >>>>>> I am not sure whether for the use purposes of the tags this difference >>>>>> is very important, but it is worth noting. >>>>>> >>>>>> >>>>>> As Joseph suggested, it may be better to encourage users of these tags >>>>>> to use the C2x attribute syntax if they are concerned with precisely >>>>>> which construct the tag applies. >>>>>> >>>>>> This would also be a way around any issues in handling the attributes >>>>>> due to the GNU syntax. >>>>>> >>>>>> I tried a few test cases using C2x syntax BTF type tags with a >>>>>> clang-15 build, but ran into some issues (in particular, some of the >>>>>> tag attributes being ignored altogether). I couldn't find confirmation >>>>>> whether C2x attribute syntax is fully supported in clang yet, so maybe >>>>>> this isn't expected to work. Do you know whether the C2x syntax is >>>>>> fully supported in clang yet? >>>>> >>>>> Actually, I don't know either. But since the btf decl_tag and type_tag >>>>> are also used to compile linux kernel and the minimum compiler version >>>>> to compile kernel is gcc5.1 and clang11. I am not sure whether gcc5.1 >>>>> supports c2x or not, I guess probably not. So I think we most likely >>>>> cannot use c2x syntax. >>>> >>>> Okay, I think we can guard btf_tag's with newer compiler versions. >>>> What kind of c2x syntax you intend to use? I can help compile kernel >>>> with that syntax and llvm15 to see what is the issue and may help >>>> fix it in clang if possible. >>> >>> I am thinking to use the [[]] C2x standard attribute syntax. The >>> syntax makes it quite clear to which entity each attribute applies, >>> and in my opinion is a little more intuitive/less surprising too. >>> It's documented here (PDF): >>> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2731.pdf >>> See sections 6.7.11 for the syntax and 6.7.6 for >>> declarations. Section 6.7.6.1 specifically describes using the >>> attribute syntax with pointer declarators. >>> The attribute syntax itself for BTF tags is: >>>   [[clang::btf_type_tag("tag1")]] >>> or >>>   [[gnu::btf_type_tag("tag1")]] >>> >>> I am also looking into whether, with the C2x syntax, we really need two >>> separate attributes (type_tag and decl_tag) at the language >>> level. It might be possible with C2x syntax to use just one language >>> attribute (e.g. just btf_tag). >>> >>> A simple declaration for a tagged pointer to an int: >>>   int * [[gnu::btf_type_tag("tag1")]] x; >>> And for the example from this thread: >>>   #define __typetag1 [[gnu::btf_type_tag("type-tag-1")]] >>>   #define __typetag2 [[gnu::btf_type_tag("type-tag-2")]] >>>   #define __typetag3 [[gnu::btf_type_tag("type-tag-3")]] >>>   int * __typetag1 * __typetag2 __typetag3 g; >>> Here each tag applies to the preceding pointer, so the result is >>> unsurprising. >>> Actually, this is where I found something that looks like an issue >>> with the C2x attribute syntax in clang. The tags 2 and 3 go missing, >>> but with no warning nor other indication. >>> Compiling this example with gcc: >>> $ ~/toolchains/bpf/bin/bpf-unknown-none-gcc -c -gbtf -gdwarf c2x.c >>> -o c2x.o --std=c2x >>> $ ~/toolchains/llvm/bin/llvm-dwarfdump c2x.o >>> 0x0000000c: DW_TAG_compile_unit >>>               DW_AT_producer    ("GNU C2X 12.0.1 20220401 >>> (experimental) -gbtf -gdwarf -std=c2x") >>>               DW_AT_language    (DW_LANG_C11) >>>               DW_AT_name    ("c2x.c") >>>               DW_AT_comp_dir    ("/home/dfaust/playpen/btf/tags") >>>               DW_AT_stmt_list    (0x00000000) >>> 0x0000001e:   DW_TAG_variable >>>                 DW_AT_name    ("g") >>>                 DW_AT_decl_file    ("/home/dfaust/playpen/btf/tags/c2x.c") >>>                 DW_AT_decl_line    (16) >>>                 DW_AT_decl_column    (0x2a) >>>                 DW_AT_type    (0x00000032 "int **") >>>                 DW_AT_external    (true) >>>                 DW_AT_location    (DW_OP_addr 0x0) >>> 0x00000032:   DW_TAG_pointer_type >>>                 DW_AT_byte_size    (8) >>>                 DW_AT_type    (0x0000004e "int *") >>>                 DW_AT_sibling    (0x0000004e) >>> 0x0000003b:     DW_TAG_LLVM_annotation >>>                   DW_AT_name    ("btf_type_tag") >>>                   DW_AT_const_value    ("type-tag-3") >>> 0x00000044:     DW_TAG_LLVM_annotation >>>                   DW_AT_name    ("btf_type_tag") >>>                   DW_AT_const_value    ("type-tag-2") >>> 0x0000004d:     NULL >>> 0x0000004e:   DW_TAG_pointer_type >>>                 DW_AT_byte_size    (8) >>>                 DW_AT_type    (0x00000061 "int") >>>                 DW_AT_sibling    (0x00000061) >>> 0x00000057:     DW_TAG_LLVM_annotation >>>                   DW_AT_name    ("btf_type_tag") >>>                   DW_AT_const_value    ("type-tag-1") >>> 0x00000060:     NULL >>> 0x00000061:   DW_TAG_base_type >>>                 DW_AT_byte_size    (0x04) >>>                 DW_AT_encoding    (DW_ATE_signed) >>>                 DW_AT_name    ("int") >>> 0x00000068:   NULL >>> >>> and with clang (changing the attribute prefix to clang:: appropriately): >>> $ ~/toolchains/llvm/bin/clang -target bpf -g -c c2x.c -o c2x.o.ll >>> --std=c2x >>> $ ~/toolchains/llvm/bin/llvm-dwarfdump c2x.o.ll >>> 0x0000000c: DW_TAG_compile_unit >>>               DW_AT_producer    ("clang version 15.0.0 >>> (https://github.com/llvm/llvm-project.git >>> f80e369f61ebd33dd9377bb42fcab64d17072b18)") >>>               DW_AT_language    (DW_LANG_C99) >>>               DW_AT_name    ("c2x.c") >>>               DW_AT_str_offsets_base    (0x00000008) >>>               DW_AT_stmt_list    (0x00000000) >>>               DW_AT_comp_dir    ("/home/dfaust/playpen/btf/tags") >>>               DW_AT_addr_base    (0x00000008) >>> 0x0000001e:   DW_TAG_variable >>>                 DW_AT_name    ("g") >>>                 DW_AT_type    (0x00000029 "int **") >>>                 DW_AT_external    (true) >>>                 DW_AT_decl_file    ("/home/dfaust/playpen/btf/tags/c2x.c") >>>                 DW_AT_decl_line    (12) >>>                 DW_AT_location    (DW_OP_addrx 0x0) >>> 0x00000029:   DW_TAG_pointer_type >>>                 DW_AT_type    (0x00000032 "int *") >>> 0x0000002e:     DW_TAG_LLVM_annotation >>>                   DW_AT_name    ("btf_type_tag") >>>                   DW_AT_const_value    ("type-tag-1") >>> 0x00000031:     NULL >>> 0x00000032:   DW_TAG_pointer_type >>>                 DW_AT_type    (0x00000037 "int") >>> 0x00000037:   DW_TAG_base_type >>>                 DW_AT_name    ("int") >>>                 DW_AT_encoding    (DW_ATE_signed) >>>                 DW_AT_byte_size    (0x04) >>> 0x0000003b:   NULL >> >> Thanks. I checked with current clang. The generated code looks >> like above. Basically, for code like below >> >> #define __typetag1 [[clang::btf_type_tag("type-tag-1")]] >> #define __typetag2 [[clang::btf_type_tag("type-tag-2")]] >> #define __typetag3 [[clang::btf_type_tag("type-tag-3")]] >> >> int * __typetag1 * __typetag2 __typetag3 g; >> >> The IR type looks like >> __typetag3 -> __typetag2 -> * (ptr1) -> __typetag1 -> * (ptr2) -> int >> >> The IR is similar to what we did if using >> __attribute__((btf_type_tag(""))), but their >> semantic interpretation is quite different. >> For example, with c2x format, >> __typetag1 applies to ptr2 >> with __attribute__ format, it applies pointee of ptr1. >> >> But more importantly, c2x format is incompatible with >> the usage of linux kernel. The following are a bunch of kernel >> __user usages. Here, __user intends to be replaced with a btf_type_tag. >> >> vfio_pci_core.h: ssize_t (*rw)(struct vfio_pci_core_device >> *vdev, char __user *buf, >> vfio_pci_core.h: char __user *buf, >> size_t count, >> vfio_pci_core.h:extern ssize_t vfio_pci_bar_rw(struct >> vfio_pci_core_device *vdev, char __user *buf, >> vfio_pci_core.h:extern ssize_t vfio_pci_vga_rw(struct >> vfio_pci_core_device *vdev, char __user *buf, >> vfio_pci_core.h: char __user >> *buf, size_t count, >> vfio_pci_core.h: void __user *arg, >> size_t argsz); >> vfio_pci_core.h:ssize_t vfio_pci_core_read(struct vfio_device >> *core_vdev, char __user *buf, >> vfio_pci_core.h:ssize_t vfio_pci_core_write(struct vfio_device >> *core_vdev, const char __user *buf, >> vringh.h: vring_desc_t __user *desc, >> vringh.h: vring_avail_t __user *avail, >> vringh.h: vring_used_t __user *used); >> vt_kern.h:int con_set_cmap(unsigned char __user *cmap); >> vt_kern.h:int con_get_cmap(unsigned char __user *cmap); >> vt_kern.h:int con_set_trans_old(unsigned char __user * table); >> vt_kern.h:int con_get_trans_old(unsigned char __user * table); >> vt_kern.h:int con_set_trans_new(unsigned short __user * table); >> vt_kern.h:int con_get_trans_new(unsigned short __user * table); >> >> You can see, we will not able to simply replace __user >> with [[clang::btf_type_tag("user")]] because it won't work >> according to c2x expectations. Hi, Thanks for checking this. I see that we probably cannot use the c2x syntax in the kernel, since it will not work as a drop-in replacement for the current uses. > > Hi Yongsong. > > I am a bit confused regarding the GNU attributes problem: our patch > supports it, but as David already noted: > >>>>> There is still the question of why the DWARF generated for this case >>>>> that I have been concerned about: >>>>> >>>>> int __typetag1 * __typetag2 __typetag3 * g; >>>>> >>>>> differs between GCC (with this series) and clang. After studying it, >>>>> GCC is doing with the attributes exactly as is described in the >>>>> Attribute Syntax portion of the GCC manual where the GNU syntax is >>>>> described. I do not think there is any problem here. >>>>> >>>>> So the difference in DWARF suggests to me that clang is not handling >>>>> the GNU attribute syntax in this particular case correctly, since it >>>>> seems to be associating __typetag2 and __typetag3 to g's type rather >>>>> than the type to which it points. > > Note the example he uses is: > > (a) int __typetag1 * __typetag2 __typetag3 * g; > > Not > > (b) int * __typetag1 * __typetag2 __typetag3 g; > > Apparently for (a) clang is generating DWARF that associates __typetag2 > and__typetag3 to g's type (the pointer to pointer) instead of the > pointer to int, which contravenes the GNU syntax rules. > > AFAIK thats is where the DWARF we generate differs, and what is blocking > us. David will correct me in the likely case I'm wrong :) Right. This is what I hoped maybe the C2x syntax could resolve. The issue I saw is that in the case (a) above, when using the GNU attribute syntax, GCC and clang produce different results. I think that the underlying cause is some subtle difference in how clang is handling the GNU attribute syntax in the case compared to GCC. To remind ourselves, here is the full example. Notice the significant difference in which objects the tags are associated with in DWARF. #define __typetag1 __attribute__((btf_type_tag("type-tag-1"))) #define __typetag2 __attribute__((btf_type_tag("type-tag-2"))) #define __typetag3 __attribute__((btf_type_tag("type-tag-3"))) int __typetag1 * __typetag2 __typetag3 * g; GCC: bpf-unknown-none-gcc -c -gdwarf -gbtf annotate.c 0x0000000c: DW_TAG_compile_unit DW_AT_producer ("GNU C17 12.0.1 20220401 (experimental) -gdwarf -gbtf") DW_AT_language (DW_LANG_C11) DW_AT_name ("annotate.c") DW_AT_comp_dir ("/home/dfaust/playpen/btf/tags") DW_AT_stmt_list (0x00000000) 0x0000001e: DW_TAG_variable DW_AT_name ("g") DW_AT_decl_file ("/home/dfaust/playpen/btf/tags/annotate.c") DW_AT_decl_line (11) DW_AT_decl_column (0x2a) DW_AT_type (0x00000032 "int **") DW_AT_external (true) DW_AT_location (DW_OP_addr 0x0) 0x00000032: DW_TAG_pointer_type DW_AT_byte_size (8) DW_AT_type (0x00000045 "int *") DW_AT_sibling (0x00000045) 0x0000003b: DW_TAG_LLVM_annotation DW_AT_name ("btf_type_tag") DW_AT_const_value ("type-tag-1") 0x00000044: NULL 0x00000045: DW_TAG_pointer_type DW_AT_byte_size (8) DW_AT_type (0x00000061 "int") DW_AT_sibling (0x00000061) 0x0000004e: DW_TAG_LLVM_annotation DW_AT_name ("btf_type_tag") DW_AT_const_value ("type-tag-3") 0x00000057: DW_TAG_LLVM_annotation DW_AT_name ("btf_type_tag") DW_AT_const_value ("type-tag-2") 0x00000060: NULL 0x00000061: DW_TAG_base_type DW_AT_byte_size (0x04) DW_AT_encoding (DW_ATE_signed) DW_AT_name ("int") 0x00000068: NULL clang: clang -target bpf -c -g annotate.c 0x0000000c: DW_TAG_compile_unit DW_AT_producer ("clang version 15.0.0 (https://github.com/llvm/llvm-project.git f80e369f61ebd33dd9377bb42fcab64d17072b18)") DW_AT_language (DW_LANG_C99) DW_AT_name ("annotate.c") DW_AT_str_offsets_base (0x00000008) DW_AT_stmt_list (0x00000000) DW_AT_comp_dir ("/home/dfaust/playpen/btf/tags") DW_AT_addr_base (0x00000008) 0x0000001e: DW_TAG_variable DW_AT_name ("g") DW_AT_type (0x00000029 "int **") DW_AT_external (true) DW_AT_decl_file ("/home/dfaust/playpen/btf/tags/annotate.c") DW_AT_decl_line (11) DW_AT_location (DW_OP_addrx 0x0) 0x00000029: DW_TAG_pointer_type DW_AT_type (0x00000035 "int *") 0x0000002e: DW_TAG_LLVM_annotation DW_AT_name ("btf_type_tag") DW_AT_const_value ("type-tag-2") 0x00000031: DW_TAG_LLVM_annotation DW_AT_name ("btf_type_tag") DW_AT_const_value ("type-tag-3") 0x00000034: NULL 0x00000035: DW_TAG_pointer_type DW_AT_type (0x0000003e "int") 0x0000003a: DW_TAG_LLVM_annotation DW_AT_name ("btf_type_tag") DW_AT_const_value ("type-tag-1") 0x0000003d: NULL 0x0000003e: DW_TAG_base_type DW_AT_name ("int") DW_AT_encoding (DW_ATE_signed) DW_AT_byte_size (0x04) 0x00000042: NULL