From patchwork Wed Mar 16 23:37:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12783299 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F805C433F5 for ; Wed, 16 Mar 2022 23:37:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241623AbiCPXim (ORCPT ); Wed, 16 Mar 2022 19:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237131AbiCPXim (ORCPT ); Wed, 16 Mar 2022 19:38:42 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C61F15A3B for ; Wed, 16 Mar 2022 16:37:27 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 22GHCfHr029189 for ; Wed, 16 Mar 2022 16:37:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=Pqu/MEAH1ixxtIzLUti8c4mcK/i+RDDkPIVgurjQb9E=; b=m53HU7tuGI8kkUG0qwJwu+x8awbCvonKg/I7c3LlJ1sA/cHQ/DIc/aiYlb2qAGRjwiwv Hu2k7uEC9zXymhQB+0ofh6q6k5EAJjX/02y3p5FsLPzTF9wCKWg2gyD1cOCWtKQm2At2 FTHZeJfQ0horRRy0PRWKQz7310+QSEX7xt8= Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2106.outbound.protection.outlook.com [104.47.70.106]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3et9d0m35c-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 16 Mar 2022 16:37:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cWpgO4VepgUCV4XGryYomHtD3+PaqulDilsSascli0iYvPPFquGHmASYwGt624XZqOB58QVBS8QGPaF/kNFF9P72C2bqVyXilpWFcpruR14F8DufD4OWrLgB9qZ4N/3mmQvi0c+vbsJct2bPBuC7nPPDlc9cDBu5gOdpXQLNnzRiAarXQtSwalagBgteftOsKf71vkQXHLOius3CVPlMIy6eJQQxdNATiHArfKpD0cRJVHJBVmY/UL8iZyqQXtt+nj9NwSRH/R+aQJlDJ0E8sKgeNHqI7Tvj4sdJkihuHB5EA1hJJANOPasCc2gkZnjPbJBXosE+rYIKaHWEqpdhwg== 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=Pqu/MEAH1ixxtIzLUti8c4mcK/i+RDDkPIVgurjQb9E=; b=hpRrJFSR1cWLF+81fz+sONZ8zV7x/0Aq1bAk6uYhCds0jkLmCPLqvi/3syjxWps1NQYEbNk9GWOGDEfQe4lJKjzFV+kLjWsKxgOiGezbbjrTdrR0jO36JOPMpnKmPTehdJWQJa7bN6oZSgi3k1wESM9zmfD1reOP72tIB7wNYuhE7Vk5KAWIhVQLzfS7w9h4hFl1SgxzfJGLTguaNHCh+7zhxa/vA0xz903bqI0zL0vKK63+kJswdGhsjUnLPhn9CpnUigX6mCoq6FEYIiiADfMMd+CsMNK7K73TfLYJztKPDuYDeLu9mI3Vx8WQ2ZXE6XL3NDCdUbtAFzLkuptE4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by DM5PR1501MB2182.namprd15.prod.outlook.com (2603:10b6:4:a4::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Wed, 16 Mar 2022 23:37:24 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::90c1:20f8:4fc6:d7a3]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::90c1:20f8:4fc6:d7a3%6]) with mapi id 15.20.5081.014; Wed, 16 Mar 2022 23:37:24 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v4 1/5] libbpf: .text routines are subprograms in strict mode Thread-Topic: [PATCH bpf-next v4 1/5] libbpf: .text routines are subprograms in strict mode Thread-Index: AQHYOY7JGutuEwujg0eGCtq27xBI8Q== Date: Wed, 16 Mar 2022 23:37:24 +0000 Message-ID: <018de8d0d67c04bf436055270d35d394ba393505.1647473511.git.delyank@fb.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b842a929-f05c-4924-8085-08da07a5ec7f x-ms-traffictypediagnostic: DM5PR1501MB2182:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: VgRF73t9BKNaxtxJ24K+WRoPlNYZoBdK1Q5uGhaWQQDxHQQiCV+JNCJj8IXq4vgov11MWarLDJlPHz83nlXjK8JCBCS2LfWesder5XKHRlcEvNLUab1AVXl+F3rsr3bQycRTMzP5uH8/f9cvmduZQlIUighbIqifICoCTCUkSjiQ5LU/wpr1cfvRDZLyXji0lu7TRmo1HG6HNUqLo7/tsvgQ/TUuHV/oTAljwJbfjkma29KYQ0S3FXeDQ02wJIbkpkQOeD41EKqt5Id0yYSDIsV0hqz3wB/X7IlZ6K5IgBOaN1VPN7tidw71HI29nLTnKjqpA9zbra0ahMBPiRlgp7FcalqaFiiaxdKOZSg8rairBHi4NShgYkum/EZpTyEvJal2IdH6QDXqSnkP4ztAw1bH9wtii12HbCMwV/EKVplsGSM1qrWfWut3zLf/HvnD/G79WPxzyuRwBmo7HJGA9T/M4eBUmX941+ZpUlqxekOj+8evJ5d+tHcjm9sTkNG6bNesChJ9ZxvqZuhlwNFZSYdCumhIOdttDaoZv8WHTOnjGxsXOc+9bGRJksnEdqKSE0eDtjL6dy/vcba/NXJ1oiRbbylPFJgdrnpBEzTXBWxDaDqZUXJ6QYFS2MqmA8XAfvrAfUSa6C+8VIwOSJNLJ1tfa0Nzs8Vo9sh45P8gZxluGxBxUxw3U82rvX5OQ4omaRlJBc0YrsxpBw3YfQoZVA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(8936002)(2616005)(5660300002)(110136005)(316002)(38070700005)(6486002)(71200400001)(508600001)(64756008)(8676002)(6512007)(122000001)(6506007)(66476007)(66446008)(86362001)(76116006)(66946007)(66556008)(91956017)(38100700002)(36756003)(186003)(2906002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?JfLgIeTuP6J0BoF4KVlnXp6?= =?iso-8859-1?q?1CzAwLU6OfMkZ0GSlcOIREjWroGO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dIaQc?= =?iso-8859-1?q?y6gGSqU5qe9J9Hoq7i2URFp3ArfynMZIjTDR+Aj9AwXUvjmOlP0JZJ1kU+SF?= =?iso-8859-1?q?7aJmI0ep+gX1yN8DMUewRDPSKA5Mf6I+394VTKODXXNOSRT0Ww/hbP/IpBqr?= =?iso-8859-1?q?0iYY9vB5xrgtaiXv5K+6ChyrFuk4RnnE0z7duR/YCW/pByrE7RZoDoGmlf2x?= =?iso-8859-1?q?L0koZkS69/ULvZ5dUEdiKz27+i/hDCYNdloqT2NbMI2SupdbIy/E7rpCi3yp?= =?iso-8859-1?q?1NB5nN4Oc2/ukUiAO8l/SiQe8spTfv7IXZtZnSCbjzizC1xzM8ihtJHrFCAC?= =?iso-8859-1?q?XvUCUn1zRtJTpB/9Du+0ecc039RwlIdEKRew7TRJIS7vglOAodS7FR1bxhQ5?= =?iso-8859-1?q?2tujMoE00leQfZ16WrJXfeg6XogIUkrf9DR2KbysIpwCM7nIkQ/7L4m6a5LQ?= =?iso-8859-1?q?E9AXP7pe2sRg4UA34NlRa40JW+imVa9xx4FJiTbASfDUxiK9pef7b6wOjr3b?= =?iso-8859-1?q?mK1IcUuXDTqXU3pNo5ZWPjFweWcIRM5HA2XtUh0HnQ820I6k+d1gw1LC0Cyn?= =?iso-8859-1?q?xchBINzUmT5lrw+pXjvE229fiUL1aQw=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b842a929-f05c-4924-8085-08da07a5ec7f X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2022 23:37:24.4185 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: WO2BxUmG5LL3DI6hGDW3iU/cg5+ZOBmNxEvs7nb+3/YnobNVyXKoWawx5vii3weN X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1501MB2182 X-Proofpoint-ORIG-GUID: Q5_5jMSK-Gwr595lIBX_wB9UtptoKEsY X-Proofpoint-GUID: Q5_5jMSK-Gwr595lIBX_wB9UtptoKEsY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-16_09,2022-03-15_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Currently, libbpf considers a single routine in .text to be a program. This is particularly confusing when it comes to library objects - a single routine meant to be used as an extern will instead be considered a bpf_program. This patch hides this compatibility behavior behind the pre-existing SEC_NAME strict mode flag. Signed-off-by: Delyan Kratunov --- tools/lib/bpf/libbpf.c | 7 +++++++ tools/lib/bpf/libbpf_legacy.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 43161fdd44bb..aa26163e4ca1 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3832,7 +3832,14 @@ static bool prog_is_subprog(const struct bpf_object *obj, * .text programs are subprograms (even if they are not called from * other programs), because libbpf never explicitly supported mixing * SEC()-designated BPF programs and .text entry-point BPF programs. + * + * In libbpf 1.0 strict mode, we always consider .text + * programs to be subprograms. */ + + if (libbpf_mode & LIBBPF_STRICT_SEC_NAME) + return prog->sec_idx == obj->efile.text_shndx; + return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1; } diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h index a283cf031665..d7bcbd01f66f 100644 --- a/tools/lib/bpf/libbpf_legacy.h +++ b/tools/lib/bpf/libbpf_legacy.h @@ -54,6 +54,10 @@ enum libbpf_strict_mode { * * Note, in this mode the program pin path will be based on the * function name instead of section name. + * + * Additionally, routines in the .text section are always considered + * sub-programs. Legacy behavior allows for a single routine in .text + * to be a program. */ LIBBPF_STRICT_SEC_NAME = 0x04, /*