Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3783475ioo; Wed, 25 May 2022 08:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDdKMkx6q8ebSFAmsK1QAdZMBLCdJVSB3rcZRTN9j7bGCzX2opvTcXqIzBHIwzLv4hhH2D X-Received: by 2002:a05:6402:1d50:b0:42b:6da9:ed34 with SMTP id dz16-20020a0564021d5000b0042b6da9ed34mr15502044edb.333.1653491095243; Wed, 25 May 2022 08:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653491095; cv=none; d=google.com; s=arc-20160816; b=P7S8dcQVNP/xqIGswoK9fafSG9+mZZb/POOgexf9Toc21rcxf8iR91Xy+bm6fCxJx1 BIQef5BHJ5Cw8YY7iF5+Of53HcVPMd+reZJcFtMrkFnCr4UpGGDWuII6jEWwPmL4145e BiKFmXXXg1ie/Flfpd2IJxIY3tgsb0Toa5CwPvX00kJD/mg5tXbEMgY4UU3jHuiw+tW8 gqZLDSIWaC7c2WbWvJ/tCDtvL0Kwuwthm4NnP11vZad0Ka4C//ENtdf92yZRkN+HReNN hgOYzH7qvJebztf1QHkuXKEXcVkNInMz+DbUuZhoChqMGpqghDoq2OUKf15OTWTu2674 /LgQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ot7igmJDFE6q+HXRmqQ1m1vgOsUsvElSU/w3uGfRtTQ=; b=U1lecBtFHOc+u0L8c+jyDwCrVt59tP8cu2Y7nwIxIF1EkOTGcKbsmDcH3MDpC6hkoV 3xiXu6QEEkHtKSuxnPB/spHeRHjjQn3po2ASQCqSC6nKiWRoy4i55flzoQTnwrkTlDN4 daRMvMjVbQ6MHGrtVB/NvLEEPE/KMiKJM/ikHB5bHz2wxhbnbbO2xTMgf1u/H5vbDM5b fXhrA6B0IuZ54Z3RPTPbndpCe0T1qiRCAx+x5bJMRpkwdQv6d++bCadODUDav+dw+uxL JPNKuY4nfEnkNfKAKMRJIz7zwrWph+j9Z2D/XiOmLtMDvi2hZGW164ZVJMK/bNJOqhYh r0Ew== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd8-20020a170907968800b006e86856a2c0si8343662ejc.704.2022.05.25.08.04.26; Wed, 25 May 2022 08:04:55 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237696AbiEXNSd (ORCPT + 99 others); Tue, 24 May 2022 09:18:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234146AbiEXNSW (ORCPT ); Tue, 24 May 2022 09:18:22 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5093C972B6 for ; Tue, 24 May 2022 06:18:21 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4L6vs11Rxvz9t9d; Tue, 24 May 2022 15:18:13 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fk1vbvlNobkz; Tue, 24 May 2022 15:18:13 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4L6vrx6zRKz9t9f; Tue, 24 May 2022 15:18:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id DBF4D8B78C; Tue, 24 May 2022 15:18:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id MDZFVzOvTcNG; Tue, 24 May 2022 15:18:09 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.153]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 281A48B779; Tue, 24 May 2022 15:18:09 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 24ODI0Pl4109106 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 24 May 2022 15:18:00 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 24ODI0aQ4109105; Tue, 24 May 2022 15:18:00 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , peterz@infradead.org, aik@ozlabs.ru, sv@linux.ibm.com, rostedt@goodmis.org, jpoimboe@redhat.com, naveen.n.rao@linux.vnet.ibm.com, mbenes@suse.cz Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [RFC PATCH v2 7/7] objtool/powerpc: Add --mcount specific implementation Date: Tue, 24 May 2022 15:17:47 +0200 Message-Id: <6ab54c456e6763b520ea2ee1c705aaec0015a5d4.1653398233.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1653398265; l=4495; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=gb2Go7BRzqF5cnEvT4VmueTHHrvWKKfQkE/YPHqKWig=; b=B6lzUqJXvN7ZLODHflfvwh8lcGqttMmdTdDzGcqx/5J4dShgnyb/CEJ7BrMZq0ehMEkMWtqvzrDN zPv8l/SJDpYUaKZnuPx15SiHWJsVouUJLAIvg3MYc20G7c35MuPT X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: Sathvika Vasireddy This patch enables objtool --mcount on powerpc, and adds implementation specific to powerpc. Signed-off-by: Sathvika Vasireddy Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + tools/objtool/arch/powerpc/decode.c | 14 ++++++++++++++ tools/objtool/check.c | 12 +++++++----- tools/objtool/elf.c | 15 +++++++++++++++ tools/objtool/include/objtool/elf.h | 1 + 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 7c01229dd2e3..5ef8bf8eb202 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -233,6 +233,7 @@ config PPC select HAVE_NMI if PERF_EVENTS || (PPC64 && PPC_BOOK3S) select HAVE_OPTPROBES select HAVE_OBJTOOL + select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL select HAVE_PERF_EVENTS select HAVE_PERF_EVENTS_NMI if PPC64 select HAVE_PERF_REGS diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c index eb1542d155fe..048bb4cd2838 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -41,12 +41,26 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec struct list_head *ops_list) { u32 insn; + unsigned int opcode; *immediate = 0; insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset)); *len = 4; *type = INSN_OTHER; + opcode = (insn >> 26); + + switch (opcode) { + case 18: /* bl */ + if ((insn & 3) == 1) { + *type = INSN_CALL; + *immediate = insn & 0x3fffffc; + if (*immediate & 0x2000000) + *immediate -= 0x4000000; + } + break; + } + return 0; } diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 7f0dc504dd92..70be5a72e838 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -834,7 +834,7 @@ static int create_mcount_loc_sections(struct objtool_file *file) memset(loc, 0, size); if (elf_add_reloc_to_insn(file->elf, sec, idx, - R_X86_64_64, + elf_reloc_type_long(file->elf), insn->sec, insn->offset)) return -1; @@ -2185,7 +2185,7 @@ static int classify_symbols(struct objtool_file *file) if (arch_is_retpoline(func)) func->retpoline_thunk = true; - if (!strcmp(func->name, "__fentry__")) + if ((!strcmp(func->name, "__fentry__")) || (!strcmp(func->name, "_mcount"))) func->fentry = true; if (is_profiling_func(func->name)) @@ -2261,9 +2261,11 @@ static int decode_sections(struct objtool_file *file) * Must be before add_jump_destinations(), which depends on 'func' * being set for alternatives, to enable proper sibling call detection. */ - ret = add_special_section_alts(file); - if (ret) - return ret; + if (opts.stackval || opts.orc || opts.uaccess || opts.noinstr) { + ret = add_special_section_alts(file); + if (ret) + return ret; + } ret = add_jump_destinations(file); if (ret) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 63218f5799c2..34b1c6817a5e 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -793,6 +793,21 @@ elf_create_section_symbol(struct elf *elf, struct section *sec) return sym; } +int elf_reloc_type_long(struct elf *elf) +{ + switch (elf->ehdr.e_machine) { + case EM_X86_64: + return R_X86_64_64; + case EM_PPC64: + return R_PPC64_ADDR64; + case EM_PPC: + return R_PPC_ADDR32; + default: + WARN("unknown machine..."); + exit(-1); + } +} + int elf_add_reloc_to_insn(struct elf *elf, struct section *sec, unsigned long offset, unsigned int type, struct section *insn_sec, unsigned long insn_off) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index c720c4476828..d10f4701715b 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -152,6 +152,7 @@ static inline int elf_class_size(struct elf *elf) struct elf *elf_open_read(const char *name, int flags); struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr); +int elf_reloc_type_long(struct elf *elf); int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, unsigned int type, struct symbol *sym, s64 addend); int elf_add_reloc_to_insn(struct elf *elf, struct section *sec, -- 2.35.3