Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1542971ybg; Tue, 2 Jun 2020 12:53:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZOaSYBnnrWVJTMa8LeeMsKDZ42lwSy2LKIZvx2/wBYgL9DsiMuDoHRPD3XokgJRMFM7vv X-Received: by 2002:a50:e1c9:: with SMTP id m9mr26820645edl.196.1591127630034; Tue, 02 Jun 2020 12:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591127630; cv=none; d=google.com; s=arc-20160816; b=w0R+4sXJ17CzQ46E3pybEbd2WFA3jVHEJRtzI42hMKdcV/RviGuHxlvFOmh3eBRs3f ETBwrME5OrvLU7YrGiZVbInTWwb7euujGPUnd5pu8TOkRPuFBw2QqmgiEoou4WdXHaHZ oDQ8H+9TKWKXxkOnmlE8xuzEZ8VcFzmRY2xR5XeWd4VTxCLbhgWlfFKGOsGSuKhccKgV Yd6XTY7k3FIIi/8UoK0kj41PwDKghnBSQWGlkriVOX7YX3qjLvDLJDIlA7BhGo0zObCP UGvVzIBefTRnTpN0rDWU8BeNIBQA9bs0RhbVlEugBKkzDmhjunwrWEykDEXk9oae0CSn 4p7w== 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=rSCselIPYeHoPWYMPX40rOka3duIFEN7Um/7xDhIY0k=; b=PaRUtlc1k64VjV91vwAA7wneJrNS1mnLMqhBNx1ooWD7RtxmL00ASNqbIBR2lvW293 gkmqrTh0BjbgpSCijslspIQrxSHYegeICKTkReax+X7zcHShk13tPT8XwQLL+Dr/AGSf RGbmZR3yK5nOcQebASjjc19zJAuHFAttRpYYbI5TtNbmPzwVNshT1Eafc2OT1bc0qlx9 RAwSesZdgyquSNxg9v/R1elUFu1OF9WwXNsPXVKzHiBnIV5sV2YMvM4/qnaOp4LF5uHk Eb1knlj+ZKcSDPBpYwDx3tzTwryWRaN6CPn+p9yFsuzw3BNdYnzqP8PlgNtA4CzqEJAA t6Hg== 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 d18si2036590edj.393.2020.06.02.12.53.26; Tue, 02 Jun 2020 12:53:50 -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 S1728451AbgFBTvQ (ORCPT + 99 others); Tue, 2 Jun 2020 15:51:16 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:36862 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728346AbgFBTvC (ORCPT ); Tue, 2 Jun 2020 15:51:02 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Tue, 2 Jun 2020 12:50:57 -0700 Received: from sc9-mailhost3.vmware.com (unknown [10.200.192.49]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 4D6CA40BED; Tue, 2 Jun 2020 12:50:58 -0700 (PDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Sami Tolvanen , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v4 15/32] objtool: mcount: Move find_section_sym_index() Date: Tue, 2 Jun 2020 12:50:08 -0700 Message-ID: X-Mailer: git-send-email 2.25.1 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 This function is no longer dependent upon the old recordmcount ELF wrapper code -- it doesn't use the wrapper's Elf_* types nor does it call wrapped functions. Move it into the C file. Signed-off-by: Matt Helsley --- tools/objtool/recordmcount.c | 41 ++++++++++++++++++++++++++++++++ tools/objtool/recordmcount.h | 46 +----------------------------------- 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/tools/objtool/recordmcount.c b/tools/objtool/recordmcount.c index 24090f36d26d..6150af8d67ce 100644 --- a/tools/objtool/recordmcount.c +++ b/tools/objtool/recordmcount.c @@ -482,6 +482,47 @@ static int (*is_fake_mcount)(struct reloc const *reloc) = fn_is_fake_mcount; static const unsigned int missing_sym = (unsigned int)-1; +/* + * Find a symbol in the given section, to be used as the base for relocating + * the table of offsets of calls to mcount. A local or global symbol suffices, + * but avoid a Weak symbol because it may be overridden; the change in value + * would invalidate the relocations of the offsets of the calls to mcount. + * Often the found symbol will be the unnamed local symbol generated by + * GNU 'as' for the start of each section. For example: + * Num: Value Size Type Bind Vis Ndx Name + * 2: 00000000 0 SECTION LOCAL DEFAULT 1 + */ +static int find_section_sym_index(unsigned const txtndx, + char const *const txtname, + unsigned long *const recvalp, + unsigned int *sym_index) +{ + struct symbol *sym; + struct section *txts = find_section_by_index(lf, txtndx); + + if (!txts) { + fprintf(stderr, "Cannot find section %u: %s.\n", + txtndx, txtname); + return missing_sym; + } + + list_for_each_entry(sym, &txts->symbol_list, list) { + if ((sym->bind == STB_LOCAL) || (sym->bind == STB_GLOBAL)) { + /* function symbols on ARM have quirks, avoid them */ + if (lf->ehdr.e_machine == EM_ARM + && sym->type == STT_FUNC) + continue; + + *recvalp = sym->sym.st_value; + *sym_index = sym->idx; + return 0; + } + } + fprintf(stderr, "Cannot find symbol for section %u: %s.\n", + txtndx, txtname); + return missing_sym; +} + /* 32 bit and 64 bit are very similar */ #include "recordmcount.h" #define RECORD_MCOUNT_64 diff --git a/tools/objtool/recordmcount.h b/tools/objtool/recordmcount.h index c7ce6345089d..98cf9eea6074 100644 --- a/tools/objtool/recordmcount.h +++ b/tools/objtool/recordmcount.h @@ -21,7 +21,6 @@ #undef mcount_adjust #undef sift_rel_mcount #undef nop_mcount -#undef find_section_sym_index #undef has_rel_mcount #undef tot_relsize #undef do_func @@ -41,7 +40,6 @@ # define append_func append64 # define sift_rel_mcount sift64_rel_mcount # define nop_mcount nop_mcount_64 -# define find_section_sym_index find64_section_sym_index # define has_rel_mcount has64_rel_mcount # define tot_relsize tot64_relsize # define do_func do64 @@ -61,7 +59,6 @@ # define append_func append32 # define sift_rel_mcount sift32_rel_mcount # define nop_mcount nop_mcount_32 -# define find_section_sym_index find32_section_sym_index # define has_rel_mcount has32_rel_mcount # define tot_relsize tot32_relsize # define do_func do32 @@ -270,47 +267,6 @@ static int nop_mcount(struct section * const rels, return 0; } -/* - * Find a symbol in the given section, to be used as the base for relocating - * the table of offsets of calls to mcount. A local or global symbol suffices, - * but avoid a Weak symbol because it may be overridden; the change in value - * would invalidate the relocations of the offsets of the calls to mcount. - * Often the found symbol will be the unnamed local symbol generated by - * GNU 'as' for the start of each section. For example: - * Num: Value Size Type Bind Vis Ndx Name - * 2: 00000000 0 SECTION LOCAL DEFAULT 1 - */ -static int find_section_sym_index(unsigned const txtndx, - char const *const txtname, - unsigned long *const recvalp, - unsigned int *sym_index) -{ - struct symbol *sym; - struct section *txts = find_section_by_index(lf, txtndx); - - if (!txts) { - fprintf(stderr, "Cannot find section %u: %s.\n", - txtndx, txtname); - return missing_sym; - } - - list_for_each_entry(sym, &txts->symbol_list, list) { - if ((sym->bind == STB_LOCAL) || (sym->bind == STB_GLOBAL)) { - /* function symbols on ARM have quirks, avoid them */ - if (lf->ehdr.e_machine == EM_ARM - && sym->type == STT_FUNC) - continue; - - *recvalp = sym->sym.st_value; - *sym_index = sym->idx; - return 0; - } - } - fprintf(stderr, "Cannot find symbol for section %u: %s.\n", - txtndx, txtname); - return missing_sym; -} - static char const *has_rel_mcount(const struct section * const rels) { const struct section *txts; @@ -398,7 +354,7 @@ static int do_func(Elf_Ehdr *const ehdr, rel_entsize = sec->sh.sh_entsize; mlocp = sift_rel_mcount(mlocp, (void *)mlocp - (void *)mloc0, &mrelp, - sec, recsym, recval, reltype); + sec, recsym, (uint_t)recval, reltype); } else if (txtname && (warn_on_notrace_sect || make_nop)) { /* * This section is ignored by ftrace, but still -- 2.20.1