Received: by 10.213.65.68 with SMTP id h4csp2119307imn; Sun, 8 Apr 2018 20:10:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx48114dT1qZPJUMnujlJJR245C3E5XB69fOxxB942EcE/x6EoYKqrZJM19Uq2a5i5nS/F6hu X-Received: by 10.98.60.207 with SMTP id b76mr28061107pfk.118.1523243455643; Sun, 08 Apr 2018 20:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243455; cv=none; d=google.com; s=arc-20160816; b=eyp0H0jOwV7LI+rFL0cYTWbe5JoUUSXUgntQY0ny9ggkM2bp5ggWtE96kcNvV+n42z HROQCsR2tEqlN3Q/KJwJj0mOoqtb/c9l3eeF4jFqGxSMAhqeL12y3YMTFzh33dSUoDHd SNTBTtkoKzP7ufWVUkcBKdUJWOWzidTaIMR2aPh2yhIxs7tP2XBZu0GgVHJMp1E6ihhg 5GkrT2j8tcm500mRDmdZ2ganm2RC0ufzs+m5OF/1oPc7j6cLTbaVcocYei8gDS6jR+SG WL9Rw5g/MNKSQgRNDNH8f83fSZwa9btWzwPb3DtmgQO4rm1KtRc4M7vp7rwZlsvETsCi cWCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=17ae+K4dBMg2CglbT4L+d89//kJsObQfpztteTXE70Q=; b=cv3johzo+tONTi0Pxc/Ax5/n0YiWFvWe0gdoX7gqmdMwINOuFVtdoLDPtjuSenmudB 8ySik3xmpMzaROHTrWNKoT2g/Qt7EiyHqBlQVKaTFQLPEJoEKHORJcdzQ819Kz9CJ6je w2qA2/1iDnu0tcAHHp+9xJuL6ZoNafu46jygBSZ+v1gJ09b0Mf+KOZzEuTvcnEQr/N54 rUK7gmwAc0RyOoWa2MLyNPs6cQP2iLdSPXqmN3jqcSkyU/r777VFx6PLv1X1vh7rPrrn 724eNbqLIJvKJuCBhkox0YJqQIb94/rIeHC7hrxW1qAL5fpNAPoSfY6fVE+wJjLylMRn ENyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=amBCsHgV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8-v6si13938740pln.484.2018.04.08.20.10.19; Sun, 08 Apr 2018 20:10:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=amBCsHgV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754234AbeDIBGG (ORCPT + 98 others); Sun, 8 Apr 2018 21:06:06 -0400 Received: from mail-co1nam03on0103.outbound.protection.outlook.com ([104.47.40.103]:45124 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933095AbeDIAjY (ORCPT ); Sun, 8 Apr 2018 20:39:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=17ae+K4dBMg2CglbT4L+d89//kJsObQfpztteTXE70Q=; b=amBCsHgVF4qjmMVvUC4m517dHbkFsX0L7Gs3Hr5LJSDsxqWsE/9TZYP2zkPnrdii6Qt4teqwdgqnzTYitidJ4XGMgRAzKH0zBtgLsxQCFPxkn7SkQV5a74ilA9tnvMW/d97awPmO2QgrmUbi97pJ8ZkoWQ7qQWmrOjeyMXKs/O4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1047.namprd21.prod.outlook.com (52.132.128.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:39:23 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:39:23 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jesper Dangaard Brouer , Daniel Borkmann , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 160/162] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Topic: [PATCH AUTOSEL for 4.4 160/162] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Index: AQHTz5ni7GKPoHAs7ki5m8buuwU1TQ== Date: Mon, 9 Apr 2018 00:29:55 +0000 Message-ID: <20180409002738.163941-160-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1047;7:t4EfFtXD+zU8/nIPnE2syJNDybSmr93kvqKUBc4+y7isBAZ0ZKNyc1x0Lrx7SCi3ZWci5N3otEZbSW3h+NhkgLAm0FmdHnH7OS6D0SD6P49ktxrNd1LdVA3WcPXfoQ2/j/suxPrVbHVV9UsdDdCvCSjl7z5BCkCbRmzEaQ82ErpgNJWRyznMBBNR3WhfsrrFr4qmuJY22hx6HeK2U0qYltYzQL15M1j1YHDob9xSeUFM0Jf+s6IdPOhFj2Tuz7EQ;20:4by2WDWz1YaMq31jYnOjxgGor1pb1JnwvmUEIEC1RN0KS8o4mVhKR7rkql2DLk/yR+fpt9xDQ3si11G/3AOiKfKmhI1tuYD0XWgTXZGZZANLEmIFsMoKvyqVu+donJP4jbJBnaGNf9fxvkv+VAWndgZloQrs9gvRC0rI7ysB6EA= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 56caa183-7081-4657-7791-08d59db256df x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1047; x-ms-traffictypediagnostic: DM5PR2101MB1047: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB1047;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1047; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(396003)(366004)(39860400002)(346002)(39380400002)(189003)(199004)(97736004)(3660700001)(2900100001)(2906002)(8936002)(11346002)(3280700002)(106356001)(446003)(68736007)(72206003)(1076002)(86612001)(25786009)(3846002)(36756003)(107886003)(6116002)(81166006)(4326008)(486006)(81156014)(6512007)(6436002)(53936002)(14454004)(8676002)(26005)(575784001)(5250100002)(86362001)(105586002)(6666003)(305945005)(186003)(10290500003)(7736002)(10090500001)(102836004)(6486002)(2616005)(5660300001)(316002)(2501003)(66066001)(22452003)(54906003)(99286004)(110136005)(478600001)(476003)(76176011)(6506007)(22906009)(142923001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1047;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Y0Qcl9rz+ZnEgT8mMeixzp6scekvY+A1/bPeBMmUggnAchdLuM+uhaswkgj/0DeCkg86Guf8kVc307EP663Lk4MsKKH7gEVK63KxT6mHrNRTjaWJSGXYmdZ7wnw2wkxezmfPfJlfg9fn0k03iUE2FAW9mrIGPpwailQymetwrDE/OGyJBM7ClKGJMYqthTpDmk3V8q4v7/7Rx9KUkNxcZXNNiE32VcO9GKbOzDg9so2kMyF6YZGO4l8VDOpdNaLBeP8ez/lvOHmNVQco8anZdaJQO9ni3CP0M32JO4NX/6km2umdoK4IaXQXSpzvQSY4MFh2fp5lru1IbkbhodKW+ChtVRwP9vDhj9iRPTfJBHqWxZtzC6H08Ge0I6eSZczKk+hHB6/IsiaI8KWOnoH1wXJrA+j7GYyBTzlZ4tFcXbU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56caa183-7081-4657-7791-08d59db256df X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:29:55.7871 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1047 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jesper Dangaard Brouer [ Upstream commit e3d91b0ca523d53158f435a3e13df7f0cb360ea2 ] V3: More generic skipping of relo-section (suggested by Daniel) If clang >=3D 4.0.1 is missing the option '-target bpf', it will cause llc/llvm to create two ELF sections for "Exception Frames", with section names '.eh_frame' and '.rel.eh_frame'. The BPF ELF loader library libbpf fails when loading files with these sections. The other in-kernel BPF ELF loader in samples/bpf/bpf_load.c, handle this gracefully. And iproute2 loader also seems to work with these "eh" sections. The issue in libbpf is caused by bpf_object__elf_collect() skipping some sections, and later when performing relocation it will be pointing to a skipped section, as these sections cannot be found by bpf_object__find_prog_by_idx() in bpf_object__collect_reloc(). This is a general issue that also occurs for other sections, like debug sections which are also skipped and can have relo section. As suggested by Daniel. To avoid keeping state about all skipped sections, instead perform a direct qlookup in the ELF object. Lookup the section that the relo-section points to and check if it contains executable machine instructions (denoted by the sh_flags SHF_EXECINSTR). Use this check to also skip irrelevant relo-sections. Note, for samples/bpf/ the '-target bpf' parameter to clang cannot be used due to incompatibility with asm embedded headers, that some of the samples include. This is explained in more details by Yonghong Song in bpf_devel_QA= . Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index e176bad19bcb..ca080a129b33 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -487,6 +487,24 @@ bpf_object__init_maps(struct bpf_object *obj, void *da= ta, return 0; } =20 +static bool section_have_execinstr(struct bpf_object *obj, int idx) +{ + Elf_Scn *scn; + GElf_Shdr sh; + + scn =3D elf_getscn(obj->efile.elf, idx); + if (!scn) + return false; + + if (gelf_getshdr(scn, &sh) !=3D &sh) + return false; + + if (sh.sh_flags & SHF_EXECINSTR) + return true; + + return false; +} + static int bpf_object__elf_collect(struct bpf_object *obj) { Elf *elf =3D obj->efile.elf; @@ -567,6 +585,14 @@ static int bpf_object__elf_collect(struct bpf_object *= obj) } else if (sh.sh_type =3D=3D SHT_REL) { void *reloc =3D obj->efile.reloc; int nr_reloc =3D obj->efile.nr_reloc + 1; + int sec =3D sh.sh_info; /* points to other section */ + + /* Only do relo for section with exec instructions */ + if (!section_have_execinstr(obj, sec)) { + pr_debug("skip relo %s(%d) for section(%d)\n", + name, idx, sec); + continue; + } =20 reloc =3D realloc(reloc, sizeof(*obj->efile.reloc) * nr_reloc); --=20 2.15.1