Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp829791rwb; Mon, 26 Sep 2022 06:26:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fso0j72yadFjL7IC1s00GsKU9rD7VuM893XXyoVBATCSAYI1cJs9AA5zKLENzNnya6e1i X-Received: by 2002:a17:907:a46:b0:782:1c1c:8141 with SMTP id be6-20020a1709070a4600b007821c1c8141mr18332138ejc.549.1664198812292; Mon, 26 Sep 2022 06:26:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198812; cv=none; d=google.com; s=arc-20160816; b=Bpw++Iah/xvyPm8ypCHVGWC+O6LdUL55VAHSVpLdsr/vQUvunEOuSninsjHtDdBT0I nw2gOs6BLYAkgw9laahggFmnpMyXe2yb/vWZU4A4tXeB/s20Nb4bvrPoK0HIB5o+BESA 33dplPT8g4spdFNmeZGEF2Rf7gQ1fEIFmscj7+mwZF53sLs9wBHd6FMwbbb0zu6A4QTR UPXPcqXruCIM6MaKZt3wpsTctFNN3963fL7v0m8kG5FK+5ZZ1Ncm3Ito1eLcuRlm4w+0 6jWIwfQbilbP5AT5TZpA0CCcjuQzS5/pvmYHvun8PJ81oRgxS62VBLeT1vNYgZporDTV EvGw== 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=liK6oC3sBqeO6ACVQIfFV7gNMQdBTV9o8r+59VK2nO0=; b=pUeWAaKZrj3I+sAsXUGkQ6gnSCd0FKvA21vi3HAIcpQ4llNNOOvEv7fRvJGDfTt4y5 bs2pFyoh4y0haPLCsLBFs1tQ5Tk23KIrVPy/yW9Dii0XHrLVDYzHp5EyeL7EVdm8egaa NrtdWNbwb2q7d9Yr9sE/ix6A8yejScCvjMhGUvcer1WQq2BfwiQt3XHvLMch1eKNWe7o 2+K56t4ZsJfHyppKGMhhLqtbW9TXqcNVfd+Hu4rmOvV+pVyTfucmhbVG9QDAF4mROPPO ebFadhLwT9LuuOszSMKevZPgt2UJMcqgONPeuDtNEe0LkERI4ABcFtWWZyccrBllJ3A1 AWSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w7MyoS64; 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 s17-20020a056402521100b00450d0a3d76dsi18648417edd.197.2022.09.26.06.26.26; Mon, 26 Sep 2022 06:26:52 -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=w7MyoS64; 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 S239005AbiIZL5S (ORCPT + 99 others); Mon, 26 Sep 2022 07:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239127AbiIZLyj (ORCPT ); Mon, 26 Sep 2022 07:54:39 -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 9B12778585; Mon, 26 Sep 2022 03:50:24 -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 9408260A4D; Mon, 26 Sep 2022 10:48:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C5C3C433C1; Mon, 26 Sep 2022 10:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189318; bh=pnveg2+UrGnBn4IrjP5QIeOLOVOzaErr8xzbOiDup+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w7MyoS64vhlBkF4oonqI33saQ0aFqOygXynMeMxBj02+XajUBvfqzLpFcsUIwWKAY p5EaRBraxXAdR7K4ZsFplMqb4iUPpgVa1h51UDR+GiZs3A8l6RAn0pzK03rUXvBMNy cfGWtD7Y3+QZ7DJwZ5F3uSNdiiS68c40WrovZWgA= 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 5.19 147/207] perf jit: Include program header in ELF files Date: Mon, 26 Sep 2022 12:12:16 +0200 Message-Id: <20220926100813.228665782@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@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 953338b9e887..02cd9f75e3d2 100644 --- a/tools/perf/util/genelf.c +++ b/tools/perf/util/genelf.c @@ -251,6 +251,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; @@ -285,6 +286,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 ae138afe6c56..b5c909546e3f 100644 --- a/tools/perf/util/genelf.h +++ b/tools/perf/util/genelf.h @@ -53,8 +53,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) @@ -62,8 +64,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