Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1845836imw; Sat, 16 Jul 2022 16:43:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tCbhkS6slsBvxBlwbTEKFqu/c79lZXLcooMGdFlTdie0gB1W8TJUITCnajM+lCdpqUG5Ji X-Received: by 2002:a17:907:a0c6:b0:72f:2293:bd04 with SMTP id hw6-20020a170907a0c600b0072f2293bd04mr1303249ejc.123.1658014982280; Sat, 16 Jul 2022 16:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658014982; cv=none; d=google.com; s=arc-20160816; b=QBQcPi/6nFja/OUN1FhfNrkfa5juxKnpwg2hqUzeIBd9mip+F6JtblphJWjVEhiExj xy5ZgqjitlxSEEbxtY8c5654QckjstFBqmoqnhTs+M29S5pghnanFAysoRBLI0169etQ 5fKlPwltyY2jmvE9NAomEX02rB6b8wgdizb/a8EaNQ+gZW8f2bcZ0xJTxQJ3ENfe4Su9 AheLDfXsUlrrpgE/ZB5JvDfqmd+oM6wOInAPIkKSwTx0/8UfWXvYiyOqJjOFfDZqf4JH yNseMoZ87v/9bPXSmgWk9iTd4SoeISPHaxzecspGS61nZDrQpq1nj6SKoCChmRIOpmbN hAwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=QvzD5+agpmv+z+EPnO126OtvixIotUEzcS1YTM2Sf54=; b=kmakwWoUh1gPUMZc7hTFmrnPhGE8kzq/86COvA/1ZB9iAsnfaiIz1V2Y03IgjaRQSt 6IxG9/SxnDtZC0CvWFrq5pqmkkY5juPkDi5V3iwhj4MH8RvOaXtPfCa4QKJYyBqYBC8Z 8/eADkccHNzcnf7odsjWR1K1SdJJTa6g+ayxWvbE6GnEtG23a7yhQ3xbH76RSdCmkEG4 cqwBwj43wonzmhz2unDxRPaSFoZYEpYy9TttJvk8KMhWAjCal2idd1Jv4m8DKPMg55qw ppDgqm0DzQjX70m9/zoK5U9KpbZ8SKb8/I99tns9+5W1hJ4nmqE3WxW9/Ga9PUy99ohM ThBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="MkHx/IkF"; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a170906378400b00726c7fc61d6si9972434ejc.851.2022.07.16.16.42.35; Sat, 16 Jul 2022 16:43:02 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b="MkHx/IkF"; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232877AbiGPXRs (ORCPT + 99 others); Sat, 16 Jul 2022 19:17:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbiGPXRi (ORCPT ); Sat, 16 Jul 2022 19:17:38 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469FC22B18 for ; Sat, 16 Jul 2022 16:17:25 -0700 (PDT) Message-ID: <20220716230953.138004117@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658013443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QvzD5+agpmv+z+EPnO126OtvixIotUEzcS1YTM2Sf54=; b=MkHx/IkFOkZ/D9EqEFMfURLeqDyMptI4jvdIi9x6qwssQXJU2ADy3Sj1ttt6G/E++K/sbL pa5LFvU156K5VBDuHZ1oOTsLNv0nS5HMP/iAmvLJAglaqvRhfO+/nP0R9ALVDukwUmlHUs J9i12CzVK617RllEgwsnrJPTGRnhBodzAKvwoMPpWUB3YaWGVUNtaA2wbick1P1ghqX4Cl evjqEtkpX65MkW61eqXpRIEBWRpj9fMpI3BiNcL2V4CfTljHpK2mIfn7V/ZsALFo8iFJ6E yrzbOhtHsx4MSr5WeO6z0JA+86vu7ZE3vmfIkn6uKTOs7+z26Coem8+6T9kv7g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658013443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QvzD5+agpmv+z+EPnO126OtvixIotUEzcS1YTM2Sf54=; b=MzsacAQSccZGhFmiqh4qA4460KcAtZYXekavesQt88ORHeNvVzZRXJmhFclaOFnaMLCRIN Z1+NOdYtx+wI5VAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Tim Chen , Josh Poimboeuf , Andrew Cooper , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , Joao Moreira , Joseph Nuzman , Steven Rostedt , "Peter Zijlstra (Intel)" Subject: [patch 08/38] objtool: Add .call_sites section References: <20220716230344.239749011@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Sun, 17 Jul 2022 01:17:22 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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: Peter Zijlstra In preparation for call depth tracking provide a section which collects all direct calls. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner --- arch/x86/kernel/vmlinux.lds.S | 7 ++++ tools/objtool/check.c | 51 ++++++++++++++++++++++++++++++++ tools/objtool/include/objtool/objtool.h | 1 tools/objtool/objtool.c | 1 4 files changed, 60 insertions(+) --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -290,6 +290,13 @@ SECTIONS *(.return_sites) __return_sites_end = .; } + + . = ALIGN(8); + .call_sites : AT(ADDR(.call_sites) - LOAD_OFFSET) { + __call_sites = .; + *(.call_sites) + __call_sites_end = .; + } #endif #ifdef CONFIG_X86_KERNEL_IBT --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -898,6 +898,49 @@ static int create_mcount_loc_sections(st return 0; } +static int create_direct_call_sections(struct objtool_file *file) +{ + struct instruction *insn; + struct section *sec; + unsigned int *loc; + int idx; + + sec = find_section_by_name(file->elf, ".call_sites"); + if (sec) { + INIT_LIST_HEAD(&file->call_list); + WARN("file already has .call_sites section, skipping"); + return 0; + } + + if (list_empty(&file->call_list)) + return 0; + + idx = 0; + list_for_each_entry(insn, &file->call_list, call_node) + idx++; + + sec = elf_create_section(file->elf, ".call_sites", 0, sizeof(unsigned int), idx); + if (!sec) + return -1; + + idx = 0; + list_for_each_entry(insn, &file->call_list, call_node) { + + loc = (unsigned int *)sec->data->d_buf + idx; + memset(loc, 0, sizeof(unsigned int)); + + if (elf_add_reloc_to_insn(file->elf, sec, + idx * sizeof(unsigned int), + R_X86_64_PC32, + insn->sec, insn->offset)) + return -1; + + idx++; + } + + return 0; +} + /* * Warnings shouldn't be reported for ignored functions. */ @@ -1252,6 +1295,9 @@ static void annotate_call_site(struct ob return; } + if (insn->type == INSN_CALL && !insn->sec->init) + list_add_tail(&insn->call_node, &file->call_list); + if (!sibling && dead_end_function(file, sym)) insn->dead_end = true; } @@ -4275,6 +4321,11 @@ int check(struct objtool_file *file) if (ret < 0) goto out; warnings += ret; + + ret = create_direct_call_sections(file); + if (ret < 0) + goto out; + warnings += ret; } if (opts.mcount) { --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -28,6 +28,7 @@ struct objtool_file { struct list_head static_call_list; struct list_head mcount_loc_list; struct list_head endbr_list; + struct list_head call_list; bool ignore_unreachables, hints, rodata; unsigned int nr_endbr; --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -106,6 +106,7 @@ struct objtool_file *objtool_open_read(c INIT_LIST_HEAD(&file.static_call_list); INIT_LIST_HEAD(&file.mcount_loc_list); INIT_LIST_HEAD(&file.endbr_list); + INIT_LIST_HEAD(&file.call_list); file.ignore_unreachables = opts.no_unreachable; file.hints = false;