Received: by 10.213.65.68 with SMTP id h4csp2137843imn; Sun, 8 Apr 2018 20:40:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx48kvR8cfC2f0jTxT1zF5RGMI6Vl9IvSeObfpr1rasD6JQZq/hZe7aFjdljbjw656pTd6Um6 X-Received: by 2002:a17:902:8283:: with SMTP id y3-v6mr3273862pln.10.1523245214458; Sun, 08 Apr 2018 20:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523245214; cv=none; d=google.com; s=arc-20160816; b=kIFlrTnU8heDVy/+ThsDDecWdvn+nkkWIwVPCKM6aK6nKTV4JeWPpV36a7mpEEgeBs ROQ2Lw4y+tXIokPniKJOPeA65S62KDdbJ1IO/aeS+T+ermznRz7XMethErg8FIuslPim UGTt3MCS2AjIVQ1n960oTlY4o1j5QbpAnQTh2vruRCiphDvGf4weKOGnU3Wg5r7y6dwa ii67GY8nESGBVcPnqjbrNPW4IN9x7r9Zjd8eqZuN/xOW59P5OpCZrj8g6Fg45xup1CzY tZtveZB0InsyS/AEKCcKwqGHb2ptULZZ6z8JjsnXYi7h9XVCXPvsBLYPLrWSTPxICteA HKHA== 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=+qpvAMdYgIhTw79DjpsxI+nZy+CP8AwwOY2QcqPWo0o=; b=admCgw/ek9MxfK/0q12vq0o/JgQcI7inAQpiTHRbizpYMpgKM8hq3UwtpI0oOVx1+t BwykbkIC2eG+BTcRVn2WMUquPeIhLf4M7/zIpLOLE8xAbv+A7Moj1rfptP0kRgo6GRkp 12no/8rEL35nKBxChV9kTH+ntG8VeSfCOkkeCHp79S0n/1xO8lymUF4SZqdgoA+SttV9 trj/qzFhYg4zgNTuDnFpfLbFJ4xgCbO3ke89yYGAB8cPQYFWzHqBCJrX9V6SC6AlqCeV ij1/yiPz/t0LIokD6rgG77FOI9B9DL7FQ1iWYFNEf+Z8UkrzamEuFW/g2Jh2aHlrK+ix h31A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=fsMENOP5; 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 p3-v6si15579856pld.512.2018.04.08.20.39.37; Sun, 08 Apr 2018 20:40:14 -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=fsMENOP5; 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 S1754314AbeDIDeb (ORCPT + 99 others); Sun, 8 Apr 2018 23:34:31 -0400 Received: from mail-bn3nam01on0108.outbound.protection.outlook.com ([104.47.33.108]:54803 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754423AbeDIAVR (ORCPT ); Sun, 8 Apr 2018 20:21:17 -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=+qpvAMdYgIhTw79DjpsxI+nZy+CP8AwwOY2QcqPWo0o=; b=fsMENOP5wx4pB6fyayDt7+bIB8OgHppIYIlyyDj0Y6CpaHSE/87dJc8ggs4DE2ksM6TT6O+ahkPjvPUSmZ4pf0l0QeUG5bZxTSNJBcQIYj6/hd7d3+jDBMUUt4b8CQYmmhF5jiNRD7EjCFPpRQwaN9ms4pUbNXTaFjGQ80yVifs= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1125.namprd21.prod.outlook.com (52.132.130.150) 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:21:12 +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:21:12 +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.15 173/189] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Topic: [PATCH AUTOSEL for 4.15 173/189] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Index: AQHTz5hfUbQW3PyWmEik3hbCaeql/A== Date: Mon, 9 Apr 2018 00:19:06 +0000 Message-ID: <20180409001637.162453-173-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB1125;7:yWKDnWHunRv41JF42h72gyWBGGvbvdGmLkxHdAhCFaqAeigDCo1YfPfClrvpb6AQHjJdtKGLeSfvZpRLLY56yfAthw6od5TD2YUF8o1+Z8W9Ni7rE6mdOYxdfy6LZeId6u7FrnXUqvROE0pMZe1QCwfVmF5PFo+J3E8k+vkyXqHMeJLDJqAZUUjGB3rhD0zNLDQuYH+KsjIxCH5WLUwx/9noBYQAjigI+f3TkDlZyeOg/o2BL2W7aXCJirfmwdXd;20:InyLBXNYftnWcFEF3eWCkMqM6URk6OJGVlD912/ebSzV9FhW1neG9MQqYbvg10xIjWH/UcYh4c/n+n9OaE/ny7uS0D38pw4ZTiG9UglC4Dbaf4C39kWvYFHuxhaOR+XjusoyS/gYO5ISLuBUEy2O+RwzYWGqL2l+xa2CqBQUAqc= X-MS-Office365-Filtering-Correlation-Id: 97352dc2-aa3a-461b-ac07-08d59dafcc98 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1125; x-ms-traffictypediagnostic: DM5PR2101MB1125: 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)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1125;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1125; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(376002)(396003)(39380400002)(39860400002)(346002)(199004)(189003)(105586002)(7736002)(8676002)(97736004)(81166006)(106356001)(81156014)(305945005)(14454004)(66066001)(1076002)(102836004)(5250100002)(478600001)(2501003)(2900100001)(22452003)(72206003)(68736007)(26005)(86362001)(575784001)(8936002)(76176011)(6506007)(6116002)(6486002)(186003)(5660300001)(3660700001)(316002)(54906003)(110136005)(25786009)(2906002)(10090500001)(6512007)(3280700002)(6666003)(10290500003)(53936002)(99286004)(86612001)(3846002)(6436002)(486006)(4326008)(2616005)(11346002)(107886003)(36756003)(476003)(446003)(22906009)(142923001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1125;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: DskgG/zL1NCCuq1gbyoA+ay27MLf1pt4I/nTBw3F8+Kqv0ZFyzV4KlVK7oq2ru3zcvDeRLACEUMcskO31m0ZorRI8U+M5kjju4NXrYjzj+jF9yrawzY7mSMxI4+JAThczJU7s2dO9fdBfTVfqZ3E+K+xw19K0+XBuX7aMYCgjlVGt9ewnX8ANKKaO88myORvdEMdw7hLlYjhwa27Ye41kMKED3ybrRrhKRD5r7iOa8tWO1Fzv3T2NRbv/3pB6zLlFYBU27mL7kJleNwLud+CX5eEvWKXDUoL2SN6pywGOwuOMg4GJnJPoKa8WwudqQZfRhZu94/kMiXmPenXSCAyIcg17vHKXPLAUmsl2KEx5Xx+Etb8arxGH1/JstyvEi8jyABnESEvdpn69OwMsM/secpnkVqcyHLZPszcpA8O2a4= 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: 97352dc2-aa3a-461b-ac07-08d59dafcc98 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:19:06.0959 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1125 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 cda652a12880..8aeedf71ea28 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -726,6 +726,24 @@ bpf_object__init_maps(struct bpf_object *obj) 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; @@ -807,6 +825,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