Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1647892ybt; Thu, 18 Jun 2020 13:49:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxomP26sRzVETgYqdRcm82rU/x4DdZ+cHVWsPztnenWrcKab/zDI8Rz5nADFOGuCE9E3D4s X-Received: by 2002:a17:906:edb6:: with SMTP id sa22mr513071ejb.393.1592513347815; Thu, 18 Jun 2020 13:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513347; cv=none; d=google.com; s=arc-20160816; b=rfJyGvQqICDxas4fvIavdQXO8/GiZtl5aIAktHZXR9xv1+4QgJuHaCArViNvyyGYdE b2wfrijj+pVNdLBNcshV5yJfFp+knrYh+2+2b9fw5DYJaZ0HQiLMZn52hCVsIVLRga1H zbaVWLl98xaydoHF1n80x08uezPFXwRZw4zW5WTlvRHEbAVKnIxWKqAEKANIcTn1WEDT qrlqdsLU1MaR3fpfsslcjodXzYeI2FJly+6COJqtij1vmZPVJe/6nPDQY9HyauVtn+xL RhM3e1qZRqFW471WJOv079l6dH5NbyP8P8vKHPLiPPTZ69lepQ21nfaw7LyJIXoJ6AGo 6Cfg== 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=f0L5xQzPGCupW6ZEqC/NCi07nnCcNWX6LV9/5hwx3lk=; b=GOJSam6Q4eM2uJqdstEMaq8V+0qKwzvedqp54dYAvRNwhioMA814jGj83K8rgFMLn4 VYwbwY9v+ZEHA3JctdqfGfeuYlo+teRmDuSwIrwFPjUjbecbFQMdPNWmToH+roQM/YUY gjGBUl3iv0Hi2V7saakilgGvumvAwAn/MbBcJd9ff/DquRZJto8/HH8pYDOTlfT7DwGZ 6a3an8htmYD4TFYZs54ohaGXFzAhx/KgUM5GTv7ZD8rbVWqa4zfaiD/SVfzlsfQlQgbT nctujjlcUiBLJHIIzWaiXDWo++NfI/pJFXy5SvOV/0/gbIACKl19bnLwLZfxJMk7ExXO YfyA== 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 ob24si2349768ejb.701.2020.06.18.13.48.45; Thu, 18 Jun 2020 13:49:07 -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 S1731691AbgFRUjz (ORCPT + 99 others); Thu, 18 Jun 2020 16:39:55 -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 S1731200AbgFRUjQ (ORCPT ); Thu, 18 Jun 2020 16:39:16 -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:09 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 04476B2656; Thu, 18 Jun 2020 16:39:12 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 18/51] objtool: mcount: Move find_section_sym_index() Date: Thu, 18 Jun 2020 13:38:04 -0700 Message-ID: <68b37fd2066c8c6709fcd4246162d856f84a5943.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 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 | 42 ++++++++++++++++++++++++++++++++ tools/objtool/recordmcount.h | 47 +----------------------------------- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/tools/objtool/recordmcount.c b/tools/objtool/recordmcount.c index 24b019b82795..2225479157e5 100644 --- a/tools/objtool/recordmcount.c +++ b/tools/objtool/recordmcount.c @@ -482,6 +482,48 @@ 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) { + /* avoid symbols with weak binding */ + 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 cf420f9f64b0..eed592954f37 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 get_shnum @@ -44,7 +43,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 get_shnum get_shnum64 @@ -67,7 +65,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 get_shnum get_shnum32 @@ -307,48 +304,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) { - /* avoid symbols with weak binding */ - 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; @@ -435,7 +390,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