Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7827593ybi; Tue, 9 Jul 2019 05:04:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUr8RZXWR9bNDB9gqtwLL4KFIKb3UjrECadM+LoEZyBWFoDgl1Na7daj4lxGItwhTHmwmN X-Received: by 2002:a63:455c:: with SMTP id u28mr30925928pgk.416.1562673860038; Tue, 09 Jul 2019 05:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562673860; cv=none; d=google.com; s=arc-20160816; b=FqtR0XTk8XANR5inuBeZSdXyFua+zj2K38i+R5Q7vAO2Sk/MqeIbiiXcJSe2yn2tHT vjB9lXkkvkeTZuHvhgVcyxOmKUEy5Huu+9v/F3NeeUh5dx9OgeIbffVy4YfNQodqpRtc GlJ07j6KVCaWoHfKWthp1dSEUNiqr2+VL2l2hE5neGBEBkdtZffQAXcztMRhbj4SfK33 crul6U9xSRCHHDpMmq+Jo4TyKhx6t2Z/lDZYgAlpwEnRVWgMG2ln69YcDCWDTBIs/MDk /TxcwuwN3I+o+vbhrvO/CaRmUhTpE1LR3VeipytigY+U84dJ4YP/ZBJZBrl8Bu8enX6U +dCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=sUzCWjUoaw1Ji9CMqL/BG3l9OM/B2xGXVBEMerddFVE=; b=LgbF+VXyfsGj3CzGAZ1ByVPpSUrcIwlm/k67+Mlzp+a7BDC/yc+pC2zcY+hMDcgZEr DXplus9OpIhOPNYYgT186tO6uFV129ijKlDfqoXsoIK1RYGBZ0lMnNLo97yB0lbE9ghN T8gs4HcMtpp6owfwKowVEWmr4tZO5LNYl+aPvUwUBoxGwxxLZcGohGsJYDB14qRFzWcF j0g+EeuRHEKepi6k7P35t2uChRlIEumvXHbSkA+mzr2xhJ+hw/Fu7V60ETMb8nHMZzON TjGZNiRiVpARJ+ZUMgEibq3aRM6TuHotolr3iBimTSHXFx+Syi3rNWLJq3yiZnu5gm1I dd+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019061801 header.b=RMvPMwwg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v25si21931531pff.274.2019.07.09.05.04.04; Tue, 09 Jul 2019 05:04:20 -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; dkim=pass header.i=@zytor.com header.s=2019061801 header.b=RMvPMwwg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbfGIMDQ (ORCPT + 99 others); Tue, 9 Jul 2019 08:03:16 -0400 Received: from terminus.zytor.com ([198.137.202.136]:51649 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726030AbfGIMDQ (ORCPT ); Tue, 9 Jul 2019 08:03:16 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x69C1L7T1901787 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 9 Jul 2019 05:01:21 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x69C1L7T1901787 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019061801; t=1562673683; bh=sUzCWjUoaw1Ji9CMqL/BG3l9OM/B2xGXVBEMerddFVE=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=RMvPMwwgwgesiPpaJDa5qTCxik5VJUZfykZ4VNA2QZdtvZ9r2F9arOcnEmI8denDc CloJhXvlTGwYn+7LnFAY8Z//rdloCEpC6szgCSwjrOvlZSzjHgv40w0LRN4lUtwEzS nhf/DMDj9Wya0nlrUT0KzY9ebivc5A0Cww7xEh+N2GzsXKSf0HjrWDH19FdNymGxyh pOR/58pt5d8Jn57V3H7MRu5Xx+nouXYrnlHX3VXSBQrUyw0cm7LMSkyb9iQY25L2fu h9r4BBkzYooLLK4Z4U3EQprqMb2C4GrPM+tqBxB3wfHdhcnkp0MidjGeFxQrjuhvC1 NVDmR+UUOQ/vw== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x69C1KFC1901784; Tue, 9 Jul 2019 05:01:20 -0700 Date: Tue, 9 Jul 2019 05:01:20 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Josh Poimboeuf Message-ID: Cc: kasong@redhat.com, peterz@infradead.org, mingo@kernel.org, songliubraving@fb.com, rostedt@goodmis.org, jpoimboe@redhat.com, linux-kernel@vger.kernel.org, daniel@iogearbox.net, bp@alien8.de, ast@kernel.org, hpa@zytor.com, tglx@linutronix.de Reply-To: jpoimboe@redhat.com, mingo@kernel.org, kasong@redhat.com, peterz@infradead.org, rostedt@goodmis.org, songliubraving@fb.com, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, ast@kernel.org, bp@alien8.de, daniel@iogearbox.net In-Reply-To: <0ba2ca30442b16b97165992381ce643dc27b3d1a.1561685471.git.jpoimboe@redhat.com> References: <0ba2ca30442b16b97165992381ce643dc27b3d1a.1561685471.git.jpoimboe@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/debug] objtool: Add support for C jump tables Git-Commit-ID: 87b512def792579641499d9bef1d640994ea9c18 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_06_12,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, DKIM_VALID_EF autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 87b512def792579641499d9bef1d640994ea9c18 Gitweb: https://git.kernel.org/tip/87b512def792579641499d9bef1d640994ea9c18 Author: Josh Poimboeuf AuthorDate: Thu, 27 Jun 2019 20:50:46 -0500 Committer: Ingo Molnar CommitDate: Tue, 9 Jul 2019 13:55:46 +0200 objtool: Add support for C jump tables Objtool doesn't know how to read C jump tables, so it has to whitelist functions which use them, causing missing ORC unwinder data for such functions, e.g. ___bpf_prog_run(). C jump tables are very similar to GCC switch jump tables, which objtool already knows how to read. So adding support for C jump tables is easy. It just needs to be able to find the tables and distinguish them from other data. To allow the jump tables to be found, create an __annotate_jump_table macro which can be used to annotate them. The annotation is done by placing the jump table in an .rodata..c_jump_table section. The '.rodata' prefix ensures that the data will be placed in the rodata section by the vmlinux linker script. The double periods are part of an existing convention which distinguishes kernel sections from GCC sections. Signed-off-by: Josh Poimboeuf Signed-off-by: Thomas Gleixner Cc: Peter Zijlstra Cc: Song Liu Cc: Kairui Song Cc: Steven Rostedt Cc: Borislav Petkov Cc: Alexei Starovoitov Cc: Daniel Borkmann Link: https://lkml.kernel.org/r/0ba2ca30442b16b97165992381ce643dc27b3d1a.1561685471.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar --- include/linux/compiler.h | 5 +++++ tools/objtool/check.c | 27 ++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 8aaf7cd026b0..f0fd5636fddb 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -116,9 +116,14 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, ".pushsection .discard.unreachable\n\t" \ ".long 999b - .\n\t" \ ".popsection\n\t" + +/* Annotate a C jump table to allow objtool to follow the code flow */ +#define __annotate_jump_table __section(".rodata..c_jump_table") + #else #define annotate_reachable() #define annotate_unreachable() +#define __annotate_jump_table #endif #ifndef ASM_UNREACHABLE diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 172f99195726..27818a93f0b1 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -18,6 +18,8 @@ #define FAKE_JUMP_OFFSET -1 +#define C_JUMP_TABLE_SECTION ".rodata..c_jump_table" + struct alternative { struct list_head list; struct instruction *insn; @@ -1035,9 +1037,15 @@ static struct rela *find_switch_table(struct objtool_file *file, /* * Make sure the .rodata address isn't associated with a - * symbol. gcc jump tables are anonymous data. + * symbol. GCC jump tables are anonymous data. + * + * Also support C jump tables which are in the same format as + * switch jump tables. For objtool to recognize them, they + * need to be placed in the C_JUMP_TABLE_SECTION section. They + * have symbols associated with them. */ - if (find_symbol_containing(rodata_sec, table_offset)) + if (find_symbol_containing(rodata_sec, table_offset) && + strcmp(rodata_sec->name, C_JUMP_TABLE_SECTION)) continue; rodata_rela = find_rela_by_dest(rodata_sec, table_offset); @@ -1277,13 +1285,18 @@ static void mark_rodata(struct objtool_file *file) bool found = false; /* - * This searches for the .rodata section or multiple .rodata.func_name - * sections if -fdata-sections is being used. The .str.1.1 and .str.1.8 - * rodata sections are ignored as they don't contain jump tables. + * Search for the following rodata sections, each of which can + * potentially contain jump tables: + * + * - .rodata: can contain GCC switch tables + * - .rodata.: same, if -fdata-sections is being used + * - .rodata..c_jump_table: contains C annotated jump tables + * + * .rodata.str1.* sections are ignored; they don't contain jump tables. */ for_each_sec(file, sec) { - if (!strncmp(sec->name, ".rodata", 7) && - !strstr(sec->name, ".str1.")) { + if ((!strncmp(sec->name, ".rodata", 7) && !strstr(sec->name, ".str1.")) || + !strcmp(sec->name, C_JUMP_TABLE_SECTION)) { sec->rodata = true; found = true; }