Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4145796pxb; Mon, 1 Feb 2021 13:47:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9grLF8FI6gY801TZCGLCcpoyZ6VUDnyQHjZ+fJAOVpG8wFmhuwDdZS6dAlOeKV3Y8AlcF X-Received: by 2002:a50:d987:: with SMTP id w7mr21648043edj.356.1612216054195; Mon, 01 Feb 2021 13:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612216054; cv=none; d=google.com; s=arc-20160816; b=UVYanKHXIGnVQhUfVHZNor6/6k7+MNeNnuInN3jmNRu18BZduTB9offBAbF395dMsm TRfKo6nmwIrQ6qPnSudnijHF3TH0l5gxAb886ZF4asLufei3VBkl/gIwYVC7GXgCYLxC Cu0qZYM/ije7B2cS+wkCN8sI80kscyQ+B9gr+zkg0HYH7yElckCjq0YQ+ygD+Y5UvCpr smorjZIY51BOqntfEpsAk2r649JCHmJxL0sYZDzYN7c3y2ssxA+SBxkvXEVvVvoOgw1H HKWM6l+A4LQJ2koMq9J6Iu83oZaFTcYyxINBGZ1w5PGDXjlVR0FzXJSrmNoS/kjqZ6DF GREQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MSmYYJUxjx/txjv3Ym8eyrnxTI/eSH9db57IFYwcwok=; b=Oi97dIQUo+h9b/rJcMssQAeIpBhyVIZjB+ir3YB2xWM1O56ccDBF0cCI57oqnpO+lG dmiMeBfyWHSlh+hk3HsFFgNZJ9h8nx3tT5fOzuyl8BWU+EGYxAmuzFyFf0dIMXNuyhEn nrXj7J3M4NWlnCBU4L3nawWs9cp/9tIZcD+AvYsG74T91Z2CGhHOK9QdfKbX7OcKE/Zd vePUcVNCBpSo6aRgtJvAeQc9SrGAWrlgsrwnnfI+UaTL0F55ojk6Bhw6/11SdpMv1lXV YpWzngrCU+seq5HzHdqHeiKaLJaN2/J1OozfFF2fqnUg5qMGeB6IlGQ+keM+kE0qtoWh JljA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZHjf6r0o; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jw9si10834221ejb.699.2021.02.01.13.47.07; Mon, 01 Feb 2021 13:47:34 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZHjf6r0o; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229527AbhBAVqD (ORCPT + 99 others); Mon, 1 Feb 2021 16:46:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50849 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhBAVqC (ORCPT ); Mon, 1 Feb 2021 16:46:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612215875; 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: in-reply-to:in-reply-to:references:references; bh=MSmYYJUxjx/txjv3Ym8eyrnxTI/eSH9db57IFYwcwok=; b=ZHjf6r0okTKGJE+rd8C5s3NRksNjGxpWh69K9LpVENXe1C8EbwfN9z25zRjCprNJy8HqVL A8jF/8GujXq4ddA1U3nTZGhxeX+KS8kqdRQN1abKr+w2lvoSQz87yhGy/TI9ukbLKyd0PQ BOD/JJGTQsjMUe0IkVumxcd3CQeik6E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-38-WO1Z_rXeMVGapiLOI2ZcNQ-1; Mon, 01 Feb 2021 16:44:30 -0500 X-MC-Unique: WO1Z_rXeMVGapiLOI2ZcNQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F5401005513; Mon, 1 Feb 2021 21:44:28 +0000 (UTC) Received: from treble (ovpn-120-118.rdu2.redhat.com [10.10.120.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0341739A50; Mon, 1 Feb 2021 21:44:24 +0000 (UTC) Date: Mon, 1 Feb 2021 15:44:23 -0600 From: Josh Poimboeuf To: Nick Desaulniers Cc: Julien Thierry , Ard Biesheuvel , Mark Brown , Catalin Marinas , Kees Cook , Linux ARM , linux-efi , linux-hardening@vger.kernel.org, LKML , Mark Rutland , Masahiro Yamada , Michal Marek , Peter Zijlstra , raphael.gault@arm.com, Will Deacon , clang-built-linux Subject: Re: [RFC PATCH 12/17] gcc-plugins: objtool: Add plugin to detect switch table on arm64 Message-ID: <20210201214423.dhsma73k7ccscovm@treble> References: <20210120173800.1660730-13-jthierry@redhat.com> <20210127221557.1119744-1-ndesaulniers@google.com> <20210127232651.rj3mo7c2oqh4ytsr@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 29, 2021 at 10:10:01AM -0800, Nick Desaulniers wrote: > On Wed, Jan 27, 2021 at 3:27 PM Josh Poimboeuf wrote: > > > > On Wed, Jan 27, 2021 at 02:15:57PM -0800, Nick Desaulniers wrote: > > > > From: Raphael Gault > > > > > > > > This plugins comes into play before the final 2 RTL passes of GCC and > > > > detects switch-tables that are to be outputed in the ELF and writes > > > > information in an ".discard.switch_table_info" section which will be > > > > used by objtool. > > > > > > > > Signed-off-by: Raphael Gault > > > > [J.T.: Change section name to store switch table information, > > > > Make plugin Kconfig be selected rather than opt-in by user, > > > > Add a relocation in the switch_table_info that points to > > > > the jump operation itself] > > > > Signed-off-by: Julien Thierry > > > > > > Rather than tightly couple this feature to a particular toolchain via > > > plugin, it might be nice to consider what features could be spec'ed out > > > for toolchains to implement (perhaps via a -f flag). > > > > The problem is being able to detect switch statement jump table vectors. > > > > For a given indirect branch (due to a switch statement), what are all > > the corresponding jump targets? > > > > We would need the compiler to annotate that information somehow. > > Makes sense, the compiler should have this information. How is this > problem solved on x86? Thus far we've been able to successfully reverse engineer it on x86, though it hasn't been easy. There were some particulars for arm64 which made doing so impossible. (I don't remember the details.) > > > Distributions (like Android, CrOS) wont be able to use such a feature as > > > is. > > > > Would a Clang plugin be out of the question? > > Generally, we frown on out of tree kernel modules for a couple reasons. > > Maintaining ABI compatibility when the core kernel changes is > generally not instantaneous; someone has to notice the ABI has changed > which will be more delayed than if the module was in tree. Worse is > when semantics subtly change. While we must not break userspace, we > provide no such guarantees within the kernel proper. > > Also, it's less likely that out of tree kernel modules have been > reviewed by kernel developers. They may not have the same quality, > use the recommended interfaces, follow coding conventions, etc.. > > Oh, did I say "out of tree kernel modules?" I meant "compiler > plugins." But it's two different sides of the same coin to me. I thought Android already relied on OOT modules. GCC plugins generally enforce the exact same GCC version for OOT modules. So there's no ABI to worry about. I assume Clang does the same? Or did I miss your point? > FWIW, I think the approach taken by -mstack-protector-guard-reg= is a > useful case study. It was prototyped as a GCC extension, then added > to GCC proper, then added to LLVM (currently only x86, but most of the > machinery is in place in the compiler to get it running on arm64). My > recommendation is to skip the plugin part and work on a standard > interface for compilers to implement, with input from compiler > developers. I like the idea. Is there a recommended forum for such discussions? Just an email to GCC/Clang development lists? -- Josh