Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp911171ybb; Fri, 10 Apr 2020 12:39:50 -0700 (PDT) X-Google-Smtp-Source: APiQypLjI5K1amuy9cLSTl78nHFJ5vNLP7n0K+KSKIBOHxbParSKjzloYiMlj+Wm7/9PChmIjnk7 X-Received: by 2002:a05:620a:88f:: with SMTP id b15mr5358011qka.118.1586547590372; Fri, 10 Apr 2020 12:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586547590; cv=none; d=google.com; s=arc-20160816; b=Q2TAogbv+rGReoGK3t2bCk5BlmawFmb+FpbouYZ9/epoGcgvm1cblKlEWvdyGwsTfI oCMbjAeivaPL4ar/cDOCCxEUZj9ZIT2/FtR+h9B3Zjw4TrPiSEN8jJeyyZQzY3rTdCFz SUkbmUv4b+xGCz9GFLwfd/pAJmgeOtIu0bT4kCZDd6kD2be/mEwwYI+gnaqUj5nzcwrA uw37KQeA8mem0B6vEwgB52CaefTj3h6i0lgDqqK0JJ6yr5W5VVKA9eRD/qygRZJ1VnW4 arPeFb0DzG3RYyjtWzQqyyNtRmGniGsS+WbDqilawTHhkrRd0pQberP3kb6BtGCh1vBe jC5A== 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=VUZmeBsYqt2vaakOWlhXSDaw1UX35eBtLMdNIq6tjqY=; b=K2X5HQsbHvJ3gOqPBtt7OgQQCr9Vyj484FfB82sjK49f9TgZNjkabQYT+UGAwAtOlq O4komFC8GU3cSliRRxJbc+EUm9hbi9qon7ZpKNz8ZnCNXgyD0BHQgcX96GTL9RfFMU7H akc19JfpMdW+72DwPFJM9kxqLdly2eEl7BTYkuvv+QzJncQHLuvNqnlOnj1+3943NOb+ rzGBnw9xyXvs3rw7EoehRGZ/+GLEI0A7oZpOI6dDcVLTF6rHoT1EbrmDtQ6C7p/W1qRS 4n63I6ptMjy92nDc6dxd1NrYbLsnzDsz8Df14Id1OJSawhOoL56g/P7UmOeFiqorNqSp B5YA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m62si1631853qte.353.2020.04.10.12.39.36; Fri, 10 Apr 2020 12:39:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727020AbgDJTiI (ORCPT + 99 others); Fri, 10 Apr 2020 15:38:08 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:36222 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726755AbgDJTiH (ORCPT ); Fri, 10 Apr 2020 15:38:07 -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; Fri, 10 Apr 2020 12:38:02 -0700 Received: from sc9-mailhost3.vmware.com (unknown [10.166.69.226]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 70C6D40C99; Fri, 10 Apr 2020 12:38:05 -0700 (PDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Julien Thierry , Ingo Molnar , Steven Rostedt , Miroslav Benes , Matt Helsley Subject: [RFC][PATCH 20/36] objtool: mcount: Move find_section_sym_index() Date: Fri, 10 Apr 2020 12:35:43 -0700 Message-ID: <83e3539584408ba4c266c0c44550db9c4371c0d1.1586468801.git.mhelsley@vmware.com> 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 6c499fe86132..61901b1c7bd3 100644 --- a/tools/objtool/recordmcount.c +++ b/tools/objtool/recordmcount.c @@ -482,6 +482,47 @@ static int (*is_fake_mcount)(struct rela const *rela) = 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 066923dd70a9..3c7afb9a2eac 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