Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp948902ybg; Wed, 29 Jul 2020 01:45:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoAsTEAybLWh2sYFaw0RSSvgTAFwg6O3bwObsI2iv6R4ZGYyTA+/xzscJbxRdHaibsaa8P X-Received: by 2002:a17:906:cc4a:: with SMTP id mm10mr26881761ejb.451.1596012318257; Wed, 29 Jul 2020 01:45:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596012318; cv=none; d=google.com; s=arc-20160816; b=VRf/fN6uOEGSwP8vc0C33thaytLZpFC/N7coRCTgKJGVLdrBvbck1EOiAEgsVVSTdP 1euAPyTkEW9gbxdmMP1aSCjiuhhn1Cpeo5atGEOw9IxZQIxwlE4W75WdOj49ApTMvMhJ mzphx82eEXe68Y9GzhOWRfeDqLTm5Nc/yYM9npiKS86srXMFDPTdLp3TDU6IeljI7a6R Nfe5MR+HK27qiGZt8kO44uY3HdqIWmGOHWi02jh32b3Jr2mGONwgh2bvLUGRFhaYJ+mv /Ba5WJ0j2rJURoHpemdmSI8ieqvUJx1XUqG/xmNUU6WEGXMDaYoSOq4zb2DUG2K+DA7O SLKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=eDpsIzFQs4UostU3d175HM40L3ctsRPQboCEBf+fEY8=; b=f+e9ke50WVpYrawa7w4nxbKUiCigCnK0D2DQKQ2X2qkiZAtkPywy8K4kG9YBDR9d6S 5b4VqFpBOl4mjOQ6UbUMRMjMsgOrHavJnkwjlRiYkiz5uWFCSKbo8MAO1/Mw26fj6jVe 1M/aSNzv/L4w3/N/vMqc0QFDjfUzEaMrAzP0vmMGktiiSUTZ8tMWC5ychEcBCuEmA5h8 5Eal8KRnCao43iH+k0Xe0lo6cMH0Iy+bTMhAmDeWT1kjJDEPXpK1GX//JBGE+96F5lsS mcq1CX5ELLYDA3AeRv8MqFvcgnDrBJDGy8ob+UJ8/6f1oxR+Z/BBSJJwg7czfIcKuLIO LgCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vAXXkxLl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p13si640918ejd.637.2020.07.29.01.44.56; Wed, 29 Jul 2020 01:45:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vAXXkxLl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbgG2Ioo (ORCPT + 99 others); Wed, 29 Jul 2020 04:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726707AbgG2Ion (ORCPT ); Wed, 29 Jul 2020 04:44:43 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49448C061794 for ; Wed, 29 Jul 2020 01:44:43 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id t18so18733443ilh.2 for ; Wed, 29 Jul 2020 01:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eDpsIzFQs4UostU3d175HM40L3ctsRPQboCEBf+fEY8=; b=vAXXkxLlLmo3Mg95KzzQSAigRBzjV4MgGii1xUhDlEMWoxREn8MvV3c+iQaa8F9Lyw H5dESD6EsGSQgaRQYd1PxIjahmNGz+jUufXsS6QXFFL4MSOx4g6UYfRWMGI4DE9SrTFu rwBeYo3gA7HBkYwZvhBlBeVrHokWBM6Oin/4lTOrDXgwpMh4jAWjEImgj0QlXMRg5jRS 1cZ17U6nQU+HO5EBvzQmhME+Y+wMHFenzKaGSNCufKfqIiMuAjoMZ/p81M45NDta+ff8 KG9M9bvv+b7VTtxaE4NhJh/li3ViMAxDNeHQQv83gTtuqYl4EsBzwGJVSnDOv7w+P4Aw EefQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eDpsIzFQs4UostU3d175HM40L3ctsRPQboCEBf+fEY8=; b=AuRxCticuPi/8O9AmBfk6EXCs+ioIYyc+qQ9IVeERPNP31T8T3m+lZmS1Eua9SjVmT f1i71YZ2YDu8qgcgOQU/5jhfvXlfh3hP3FVHe1MDTk/2WRkcN3w8mRuO+l7OsomTceLK 4uhKypEgZsiJ3BZ+9i1PI/k3z90WsJ7aQvuZPFk0pLwbpvYXRJ/JKM8/wQIKnv5cWSJs Ei/RV3fU3CERfFV7dvmNnBOGoSAmIlETLmRC7cSmfSk4UK1x0BRyiCPoDwtjon5Zv7Nk AylzMjkl0346f3s7cjbwg4YhUvVaDgvaYktZ2wtqC2KZ6mSzVhkSPZYmjaNzAMQ26nuC AoQA== X-Gm-Message-State: AOAM531U736X2eHyHtOS4gLccycdX53gP+ZO2dtCIBIPNZrIBWhnLKzs rc/2PogRJ7eNleszNdEGEsAHxr+V1ieAt7jvyMVn6nh7ilI= X-Received: by 2002:a92:1b9d:: with SMTP id f29mr980299ill.241.1596012282435; Wed, 29 Jul 2020 01:44:42 -0700 (PDT) MIME-Version: 1.0 References: <9d9a48e0-844d-8ba4-b839-92cb1af622ee@fb.com> In-Reply-To: <9d9a48e0-844d-8ba4-b839-92cb1af622ee@fb.com> From: Giuliano Procida Date: Wed, 29 Jul 2020 09:44:05 +0100 Message-ID: Subject: Re: BTF_KIND_FWD enums To: Yonghong Song Cc: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi. On Wed, 29 Jul 2020 at 08:09, Yonghong Song wrote: > > > > On 7/28/20 1:56 PM, Giuliano Procida wrote: > > Hi. > > > > Re: https://github.com/torvalds/linux/commit/9d5f9f701b1891466fb3dbb1806ad97716f95cc3 > > > > Both GCC and LLVM support forward-declared (a.k.a. incomplete) enums > > as a language extension - > > https://gcc.gnu.org/onlinedocs/gcc/Incomplete-Enums.html. > > > > (C++11 has a different notion of incomplete enum type - opaque enum > > declaration - storage size is known but enumerators are not) > > > > Forward-declared enums feature in various places in kernel code and > > allow the usual things to be done (passing around pointers to such). > > I'm curious as to if and how they are they are handled by BTF and > > whether a further change to btf_type is needed: > > > > 1. Use BTF_KIND_FWD, with another spare bit to allow up to 4 kinds of > > forward-declaration; or > > 2. use BTF_KIND_ENUM, kind_flag 0 and vlen 0 (as empty enums are > > currently illegal C); or > > #2 above is the current way. > -bash-4.4$ cat t.c > enum H; > enum H * func(enum H *arg) { return arg; } > -bash-4.4$ clang -target bpf -S -g -O2 t.c > > -bash-4.4$ > > The generated BTF enum type: > > .long 1 # BTF_KIND_ENUM(id = 2) > .long 100663296 # 0x6000000 > .long 0 > > So vlen = 0 here indicates it is a forward declaration. > Thanks, that's all clear. There is a small risk that C will follow C++ and allow zero enumerators in the future. > > > 3. use BTF_KIND_ENUM, kind_flag 1 and vlen 0. > > > > If I had a working pahole -J, I'd test this myself. :-) > > > > $ cat /tmp/en.c > > enum H; > > enum H * fun(enum H * x) { return x; } > > $ clang -Wall -Wextra -ggdb -c /tmp/en.c > > $ build/pahole -J /tmp/en.o > > Segmentation fault > > $ build/pahole -J /dev/null > > btf_elf__new: cannot get elf header. > > ctf__new: cannot get elf header. > > Segmentation fault > > -bash-4.4$ cat t.c > enum H; > enum H * func(enum H *arg) { return arg; } > -bash-4.4$ ~/work/pahole/build/pahole --version > v1.17 > -bash-4.4$ clang -Wall -Wextra -ggdb -c t.c > > -bash-4.4$ ~/work/pahole/build/pahole -JV t.o > File t.o: > [1] PTR (anon) type_id=2 > [2] ENUM H size=4 vlen=0 > [3] INT (anon) size=4 bit_offset=0 nr_bits=32 encoding=(none) > [4] FUNC_PROTO (anon) return=1 args=(1 arg) > [5] FUNC func type_id=4 > > pahole also generates vlen=0 ENUM type to indicate it is a > forward declaration. > > Maybe your pahole is too old? I tried both master and v1.17. Perhaps my libdw (Debian 0.176-1.1) is incompatible or some other library is too old. Regards, Giuliano. > > > > My interest here is that I helped add support for incomplete enums to > > libabigail which we're using to monitor kernel ABIs. > > > > Regards, > > Giuliano. > > > > (resend due to email address typo) > >