From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C56DEC169C4 for ; Tue, 12 Feb 2019 00:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95B922184E for ; Tue, 12 Feb 2019 00:47:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WqlE4DT6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728072AbfBLArq (ORCPT ); Mon, 11 Feb 2019 19:47:46 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:39576 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727791AbfBLArm (ORCPT ); Mon, 11 Feb 2019 19:47:42 -0500 Received: by mail-it1-f196.google.com with SMTP id a6so3154798itl.4; Mon, 11 Feb 2019 16:47:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aE32RtTDZIDCOZ1D1+gkqVjepLHulcS5q936jT3U5UU=; b=WqlE4DT6FQfmrB8/kp/AS9y/heekktTyaZ2gdUyTwd4+/yiAPWsynmX0AHbSQd0Gc5 LRN0z3w9UeRGeHSIwwtc4I/M7N/SVzwqKhcKaUMDy8d8de+aCIdkokD0/AJmjUS3fTSy xXmDy5/Jm00bSO+rkW17zrDV8+5WjE/Tr2sPd+euu0fFGHWX5ozgRxhCcXBcukB3Z7Hu orgsbNO7KEbBCvd+yGuXIhbmuvtTl60oe33fX8E5xP1JSFm35K7Tc1cR573Wydb4nQex NzIHgexLyfTx8bH1UwEzTZ87axlYVcFVMgPja6NUvRztyKXeuUcbBJU53vo0Q7IRLhI7 vpRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=aE32RtTDZIDCOZ1D1+gkqVjepLHulcS5q936jT3U5UU=; b=Dfog1NYoIYZCPWzeM5dkDAHhpA7IqO1F2VOwI/C1/Rz9Bix/oYtHk4ZCzu+WjQ/42l qB8JXGEDqRTtHUOA+uVBxwqv+L+v3zHhlBB6Jp1n4TX1HS81GzsT5hfRs0Ffn+Mwq4To AMOrHfUq4o+r7VP8tP9yUDagycL7qty6IlyGq2fo+oYztfDFw3Ar5hXrt+Kb+lB9zj4D 44ttXSf+v7WRFsCpvG7noTAMszebYaoc8xIonH07dxhyW2oqbnKyOINn6kRLAWlATgs0 CqNaifhRTausIfoaqe8ZsE4UKkbvCxCTzUVpQEyhKsNxn9K06hlvrOUD81yOrNAyiykb bpuQ== X-Gm-Message-State: AHQUAuYivF7cZUpBwtrjf1VlpPOLJSahFk5sDLaOZqCP20qJWS0GVowZ XKrY3T5mD1itAtpmRNB3S8Rrdo8U X-Google-Smtp-Source: AHgI3IZyZrINIsNusJmfk0jnxVlJpVNKZYV9AIvyCFaVEnBldW2uBHzI6T2DMbmsckLyvtcIfSEKwA== X-Received: by 2002:a02:8561:: with SMTP id g88mr543843jai.68.1549932461370; Mon, 11 Feb 2019 16:47:41 -0800 (PST) Received: from localhost.localdomain (mr-urb-183-235.dmisinetworks.net. [66.253.183.235]) by smtp.gmail.com with ESMTPSA id v193sm766829itv.32.2019.02.11.16.47.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 16:47:40 -0800 (PST) From: Joe Stringer To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org Subject: [PATCH bpf-next 3/4] libbpf: Support relocations for bss. Date: Mon, 11 Feb 2019 16:47:28 -0800 Message-Id: <20190212004729.535-4-joe@wand.net.nz> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190212004729.535-1-joe@wand.net.nz> References: <20190212004729.535-1-joe@wand.net.nz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The BSS section in an ELF generated by LLVM represents constants for uninitialized variables or variables that are configured with a zero value. Support initializing zeroed static data by parsing the relocations with references to the .bss section and zeroing them. Signed-off-by: Joe Stringer --- tools/lib/bpf/libbpf.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index da35d5559b22..ff66d7e970c9 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -141,6 +141,7 @@ struct bpf_program { RELO_LD64, RELO_CALL, RELO_DATA, + RELO_ZERO, } type; int insn_idx; union { @@ -222,6 +223,7 @@ struct bpf_object { int maps_shndx; int text_shndx; int data_shndx; + int bss_shndx; } efile; /* * All loaded bpf_object is linked in a list, which is @@ -901,6 +903,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags) obj->efile.reloc[n].shdr = sh; obj->efile.reloc[n].data = data; } + } else if (sh.sh_type == SHT_NOBITS && strcmp(name, ".bss") == 0) { + obj->efile.bss_shndx = idx; } else { pr_debug("skip section(%d) %s\n", idx, name); } @@ -971,6 +975,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, int text_shndx = obj->efile.text_shndx; int maps_shndx = obj->efile.maps_shndx; int data_shndx = obj->efile.data_shndx; + int bss_shndx = obj->efile.bss_shndx; struct bpf_map *maps = obj->maps; size_t nr_maps = obj->nr_maps; int i, nrels; @@ -1010,7 +1015,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, (long long) sym.st_value, sym.st_name); if (sym.st_shndx != maps_shndx && sym.st_shndx != text_shndx && - sym.st_shndx != data_shndx) { + sym.st_shndx != data_shndx && sym.st_shndx != bss_shndx) { pr_warning("Program '%s' contains unrecognized relo data pointing to section %u\n", prog->section_name, sym.st_shndx); return -LIBBPF_ERRNO__RELOC; @@ -1070,6 +1075,9 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, prog->reloc_desc[i].type = RELO_DATA; prog->reloc_desc[i].insn_idx = insn_idx; prog->reloc_desc[i].data = *static_data; + } else if (sym.st_shndx == bss_shndx) { + prog->reloc_desc[i].type = RELO_ZERO; + prog->reloc_desc[i].insn_idx = insn_idx; } } return 0; @@ -1429,6 +1437,10 @@ bpf_program__relocate(struct bpf_program *prog, struct bpf_object *obj) insn_idx = prog->reloc_desc[i].insn_idx; insns[insn_idx].imm = prog->reloc_desc[i].data; + } else if (prog->reloc_desc[i].type == RELO_ZERO) { + int insn_idx = prog->reloc_desc[i].insn_idx; + + prog->insns[insn_idx].imm = 0; } } -- 2.19.1