Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1648079ybt; Thu, 18 Jun 2020 13:49:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd4l0ai/wGXKPktEuFA7tHtU4glk2mvFvlFGSsKrq/6TDIa32pxonbhkDKA8HBaZBN2F7q X-Received: by 2002:a50:a694:: with SMTP id e20mr91095edc.144.1592513370406; Thu, 18 Jun 2020 13:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513370; cv=none; d=google.com; s=arc-20160816; b=z5Zux1Z77oe3m4baQiApwwiN6wTKB1LdvGzr2GXswGF6oB7iHcrpKzS3AwcdFXUAES 3fKJ1+uakc3jzeaIoURWpSvlTU9DhZHKls4tSw2kfOzkEMB0NAzW+UDh9wk/rhOWIH0a FuaMZB+8yTdip/7MQAD4VXQnF0dUAeOYcLF7CVbO0/7sboRQJ+6V1B1KgTgfe5U/IfBX ndD0hF0hTetMWYiqby0nJY5q9wgYPdBdEiD8LNluB9bXXIwBzaaoaIaXKO2Dq/Cz8amE iYSw2qjmX/Wcw54yP/S9fGbt/FlbZc5d87F1fuRkTrtlJemRQCS++H/o7+u+gCL58xFL 6g0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hcGM0gRuhVq+9AWQ40cKn+ixKs1DL2KYq5xM88qnFQ0=; b=RZ1CvQFjbiRWsBhf+CNc4/QE/pw53fRAJwFsEPBdgEHz1+b8PgyU/HqkRJNRtbrdP6 AiKzcWreg0EaBaSYLgQ5tMmEOqB2u1agCc5KbB6sqB4ZSecoKImuZ/QQA3x09H3Uye52 V6HVOGbCckAcK8d9ReQomnLmRGRnkSvCmIBFFN6/itaZKXSv14j7joRL2xCgwdsKQ0ht p7qHmCj8VZLavFanF+B7tCx0pTQ71HUCCQWi7A607sYXJ3Fxx7g8By9rQ8ZqfT2akJX+ /L/pOpv9/MwQhW5CvWciD1uo0QpPw2G+UDo1pwdfq2JzEb8Oil3drRUjgeJZjrznRfI5 19wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si2637928ejd.311.2020.06.18.13.49.08; Thu, 18 Jun 2020 13:49:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731989AbgFRUkY (ORCPT + 99 others); Thu, 18 Jun 2020 16:40:24 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:48844 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728225AbgFRUja (ORCPT ); Thu, 18 Jun 2020 16:39:30 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 18 Jun 2020 13:39:20 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 93D2AB2656; Thu, 18 Jun 2020 16:39:23 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 31/51] objtool: mcount: Use objtool relocation section Date: Thu, 18 Jun 2020 13:38:17 -0700 Message-ID: <19fca156c1171bb723ea98f911b4f0e38ec4d8f0.1592510545.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-002.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we add an initially-empty relocation section and share the libelf data buffer from the beginning, we can safely use objtools elf_create_reloc_section() function to simplify the code further -- use the anticipated base section name, avoid the need to set sh_info, etc. The only remaining difference between this and the old recordmcount code is we didn't set SHF_INFO_LINK so we clear the sh_flags as before. Signed-off-by: Matt Helsley --- tools/objtool/recordmcount.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tools/objtool/recordmcount.h b/tools/objtool/recordmcount.h index 1d11dfc40d09..fc6346a7eaf5 100644 --- a/tools/objtool/recordmcount.h +++ b/tools/objtool/recordmcount.h @@ -92,7 +92,7 @@ static int do_func(unsigned const reltype) GElf_Sxword r_offset = 0; struct section *sec, *mlocs, *mrels; - const char *mc_name; + const char * const mc_name = "__mcount_loc"; unsigned int rel_entsize = 0; int result = -1; @@ -119,12 +119,9 @@ static int do_func(unsigned const reltype) } is_rela = (sizeof(Elf_Rela) == rel_entsize); - mc_name = is_rela - ? ".rela__mcount_loc" - : ".rel__mcount_loc"; /* add section: __mcount_loc */ - mlocs = elf_create_section(lf, mc_name + (is_rela ? 1 : 0) + strlen(".rel"), sizeof(*mloc0), 0); + mlocs = elf_create_section(lf, mc_name, sizeof(*mloc0), 0); if (!mlocs) goto out; mlocs->sh.sh_link = 0; @@ -134,17 +131,12 @@ static int do_func(unsigned const reltype) mlocs->data->d_type = ELF_T_ADDR; /* elf_xlatetof() conversion */ /* add section .rel[a]__mcount_loc */ - mrels = elf_create_section(lf, mc_name, rel_entsize, 0); + mrels = elf_create_reloc_section(lf, mlocs, + is_rela ? SHT_RELA : SHT_REL); if (!mrels) goto out; - /* Like elf_create_rela_section() without the name bits */ - mrels->sh.sh_type = is_rela ? SHT_RELA : SHT_REL; - mrels->sh.sh_flags = 0; /* clear SHF_ALLOC */ - mrels->sh.sh_link = find_section_by_name(lf, ".symtab")->idx; - mrels->sh.sh_info = mlocs->idx; - mrels->sh.sh_addralign = 8; + mrels->sh.sh_flags = 0; /* clear SHF_INFO_LINK */ mrels->data->d_buf = mrel0; - mrels->data->d_type = is_rela ? ELF_T_RELA : ELF_T_REL; /* elf_xlatetof() conversion */ list_for_each_entry(sec, &lf->sections, list) { char const *txtname; -- 2.20.1