Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp813746rwb; Mon, 26 Sep 2022 06:15:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7tERBuGAv30mJhVx+5rmGIBYFMVkxgcK8738ZfaRZZFomBodhM+tH9I6c8AJkE6xahgqBL X-Received: by 2002:a17:906:9bf5:b0:77e:1ed1:b1b with SMTP id de53-20020a1709069bf500b0077e1ed10b1bmr18759961ejc.540.1664198131395; Mon, 26 Sep 2022 06:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198131; cv=none; d=google.com; s=arc-20160816; b=fB3HSD3feP98pybzgskyYTPlmC+M//b5bI7dUlxPYtgZJPaLVzRBQLvZ2fFq938Dg/ SvIbC7HIduF1K5lSSCc5RAiXluoc1GC1cPB/FmURPY1L0XBci3CS0K+EV4x9eKPJ9KtL YmUGoFFflGsLlRWVaQMcGyWUrlLkM872mjAwgupY84Rl+dzkpAH3MLb/lxN364Ld4i8y GamCXXmVE2MqAk07+cQdf4UgFg0pSaKzzOZNJJmOdwaPjbdyZJd5N7IVyPJPqGef17EJ zeLIHFHu0DeCrNBmro9U3u2Rz+cZwJD6VPjfBW+QMA3V8HFuNNYUpEtoikJyzCaab72A QQQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0lBZBzNlPfgBVD4cOo0hoRptvGRqtBp8/wkiIUZ+I3U=; b=sY6+kn9vQ2gNrbAJfC4J5mdf1DkTG6GM4AuSKZDSeyVXwIrAoo7/VfYoC6OwLlYFnz rfItblYdhiFzHmu7UogmcJ4jB/7gCEkGVk0WtrL+2aHzIsI9LOCVG9egFgohp+r8uqs3 m4E1nSLTPbZYIiK+UAcqzyWZQlnbgaEKn1qy/QuIoAPik1reQG2cU19PxjLZFC9I+PQv +HB6G2k+gIQn6ROUbZcROj5e/6lMdzgNkDAIB4g5MKGq7PIOjoWMrFyeOEcQp2Q748m4 IJ7vBDjpWGV6dndkLbmMXYkrXOQX9ZjgTvU3xH9zd7fOQMZBt6Qrd1KCjHG8nRqyNryZ ioIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o8VzaV0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a056402248500b004571c47b13csi5829986eda.418.2022.09.26.06.14.49; Mon, 26 Sep 2022 06:15:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o8VzaV0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235748AbiIZKcB (ORCPT + 99 others); Mon, 26 Sep 2022 06:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235863AbiIZK31 (ORCPT ); Mon, 26 Sep 2022 06:29:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 754B34F1A6; Mon, 26 Sep 2022 03:19:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DEE5460BB1; Mon, 26 Sep 2022 10:19:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEDE3C433D7; Mon, 26 Sep 2022 10:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187565; bh=BeLwktw184kwrMLr9iq2nkZ4gwzXwvVuNsdWxpXBr+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o8VzaV0ycCBl0Sg6oySDUorbt+JyYAPT+H7WFKVQ5hVSznZZMMt0b++LOgu+COCSe r5Xu9t0hLvc/EsNMsfbOYZsulGB7TT0QfW880xnTaGyLfdBtwRU56R4nYc/dPYLeTO CVF9hyEhVXmtiveTjwEgTmnDWihqc9efCrpVMU1E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Lieven Hey , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.19 47/58] perf jit: Include program header in ELF files Date: Mon, 26 Sep 2022 12:12:06 +0200 Message-Id: <20220926100743.163390892@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100741.430882406@linuxfoundation.org> References: <20220926100741.430882406@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lieven Hey [ Upstream commit babd04386b1df8c364cdaa39ac0e54349502e1e5 ] The missing header makes it hard for programs like elfutils to open these files. Fixes: 2d86612aacb7805f ("perf symbol: Correct address for bss symbols") Reviewed-by: Leo Yan Signed-off-by: Lieven Hey Tested-by: Leo Yan Cc: Leo Yan Link: https://lore.kernel.org/r/20220915092910.711036-1-lieven.hey@kdab.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/genelf.c | 14 ++++++++++++++ tools/perf/util/genelf.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c index afb8fe3a8e35..65e41e259af8 100644 --- a/tools/perf/util/genelf.c +++ b/tools/perf/util/genelf.c @@ -256,6 +256,7 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym, Elf_Data *d; Elf_Scn *scn; Elf_Ehdr *ehdr; + Elf_Phdr *phdr; Elf_Shdr *shdr; uint64_t eh_frame_base_offset; char *strsym = NULL; @@ -290,6 +291,19 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym, ehdr->e_version = EV_CURRENT; ehdr->e_shstrndx= unwinding ? 4 : 2; /* shdr index for section name */ + /* + * setup program header + */ + phdr = elf_newphdr(e, 1); + phdr[0].p_type = PT_LOAD; + phdr[0].p_offset = 0; + phdr[0].p_vaddr = 0; + phdr[0].p_paddr = 0; + phdr[0].p_filesz = csize; + phdr[0].p_memsz = csize; + phdr[0].p_flags = PF_X | PF_R; + phdr[0].p_align = 8; + /* * setup text section */ diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h index de322d51c7fe..23a7401a63d0 100644 --- a/tools/perf/util/genelf.h +++ b/tools/perf/util/genelf.h @@ -41,8 +41,10 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_ent #if GEN_ELF_CLASS == ELFCLASS64 #define elf_newehdr elf64_newehdr +#define elf_newphdr elf64_newphdr #define elf_getshdr elf64_getshdr #define Elf_Ehdr Elf64_Ehdr +#define Elf_Phdr Elf64_Phdr #define Elf_Shdr Elf64_Shdr #define Elf_Sym Elf64_Sym #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a) @@ -50,8 +52,10 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_ent #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a) #else #define elf_newehdr elf32_newehdr +#define elf_newphdr elf32_newphdr #define elf_getshdr elf32_getshdr #define Elf_Ehdr Elf32_Ehdr +#define Elf_Phdr Elf32_Phdr #define Elf_Shdr Elf32_Shdr #define Elf_Sym Elf32_Sym #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a) -- 2.35.1