Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp790501rwb; Mon, 26 Sep 2022 06:02:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JOPbfzeYSv6XcXtpz5mbk2hadIT4dh4trPo0iUkdW4fAwf10BmsohgQ40nR8+w4QsoqEd X-Received: by 2002:a17:907:25c9:b0:77b:a343:bd62 with SMTP id ae9-20020a17090725c900b0077ba343bd62mr18742856ejc.660.1664197336700; Mon, 26 Sep 2022 06:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197336; cv=none; d=google.com; s=arc-20160816; b=jwCNbOJgE9e2Co1b2UOr2SwdThx/R3DrAqIo/+hZuosnh2F8Y4jXikO13LUrT9RGt0 NqVsX3iXViCXwe1TrwJsnPFBM9JpmqRsUNge7wrMGIx/NSIYyEUSIiSi7HMeMUdOTiQF aP6IuLGRSv1GH0YWXMiYOpbwMzXQbEXBIz6Q9SFV2oqXptRS1dNP8FI3OiPUXXebfeHq Xys6ylWEPYnwdppq2YihM8OrmJ/s33V3ef2WXzvjOASao6bo23Yh8JtOJ3Gdn1zVAN83 xvrbPDM1noCMAVajPZOdRhiGaZvSw3ojzah+u0BVO37oawv1cR5VEp5Ut/S2AAFDxtHt f7Mg== 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=742K9Pz6am3UzAT4meqRrBj1gx71FtLnsi0DC1AnYaM=; b=CBCNIxRMjCB+lEqouO5qdvTHzeCCQ3EVmRIYp7qNTPxp2glQRcxc95wfp3oqLXxEsD PD95WgVu+8kCFJ7ajQmXJQuz0g9kg5FjJrOPIqCuqCMkRtzxFvItB0UxElF1nkqefwJM zwN0waOZavB+exdhlPHQ36r5kXXMr5jmepe304htCj2WYZciwmUvBjEpQb0WQqniOxBX MI8fPPKSm+NHCiMJgLax2cmvaaSV3spV2dRTw0uRAZaTHJHhZmpxQKPu11iuFHZH2l8n r03jfFuScJ5vfFret0KpfwiBR+US0Kwjmp/CFRcThvPfhM3r7rD/C7PfxsQZiXkeFKc2 HpvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DMm8wEF7; 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 y12-20020a50bb0c000000b00445f85b00f3si14280768ede.299.2022.09.26.06.01.50; Mon, 26 Sep 2022 06:02:16 -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=DMm8wEF7; 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 S236349AbiIZKpP (ORCPT + 99 others); Mon, 26 Sep 2022 06:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236318AbiIZKm7 (ORCPT ); Mon, 26 Sep 2022 06:42:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A459013DEA; Mon, 26 Sep 2022 03:24:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id D88FFB80682; Mon, 26 Sep 2022 10:24:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D61EC433D6; Mon, 26 Sep 2022 10:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187866; bh=0lhGkSCOA6U77y1Wa49mYe2WnX42qJWBP6yLtkatyMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DMm8wEF7kHdKtfd7RrQ4NgpT5LIHlEcOToNgjzkYQzZ/ym/aezCyELxSjcZ0XU4d/ P4NzbOf0lHsjZ45bvIhZ5/i7f2JRYq06ynrs/eRFt4gB1WefpFf9cax40NDl/azEkT ozHB+R6KjLiqFkKYnmzBu0cmimN/6EP1WQMToWsE= 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.4 086/120] perf jit: Include program header in ELF files Date: Mon, 26 Sep 2022 12:11:59 +0200 Message-Id: <20220926100754.188681896@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100750.519221159@linuxfoundation.org> References: <20220926100750.519221159@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 17b74aba8b9a..69744fd5db39 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 d4137559be05..ac638945b4cb 100644 --- a/tools/perf/util/genelf.h +++ b/tools/perf/util/genelf.h @@ -50,8 +50,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) @@ -59,8 +61,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