From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2379C433F5 for ; Wed, 13 Apr 2022 23:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239185AbiDMXWb (ORCPT ); Wed, 13 Apr 2022 19:22:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238856AbiDMXWY (ORCPT ); Wed, 13 Apr 2022 19:22:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E2421B7B0 for ; Wed, 13 Apr 2022 16:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892000; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WHwtgBFXaVRPDxpgXVknAcXgf6im9N3NqhP05P8+ItY=; b=JYw2gmlRdeRG6UTAZMoS7O8h5yLAhTW3AaXS03i0WQKWTr2BdKEMoFBf9qndjOMqPS4Gek 9QmRNLZloAK1gs9gpIQ4KXSodNfTLCjYfcmGNTM0Y58ZT1V4n/XIv38c9ewlK9t2GRYIgK yvhAeNgynancLXGWWMmRIiFLYw+RSj0= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-491-MAMQ73tMOnOzHf_BF5kjyg-1; Wed, 13 Apr 2022 19:19:59 -0400 X-MC-Unique: MAMQ73tMOnOzHf_BF5kjyg-1 Received: by mail-qk1-f200.google.com with SMTP id h8-20020a05620a244800b00699fb28d5e4so2135163qkn.22 for ; Wed, 13 Apr 2022 16:19:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WHwtgBFXaVRPDxpgXVknAcXgf6im9N3NqhP05P8+ItY=; b=fjxtI5O8L/pZsvyIxrc4d7GuMi3iSohJpB9GXuZMU1DU6sdcbv0BkgRcQ2f3n4OQ9M llyzJZL7n1WPHiRjMQCyS80UeDOS0Na/InyaTcW4MuHn2/SOhZQQMyXmI1/dtKD07SEk q/hNOYbqS6r+kUM0R8LG2J2MEi4FhOf3UpHgcmIuFSb7Jcw/M0JdCCX+8h/guRgbmvSf 8emtTi5dRNpPUTXVTF9u2aDdKrzEaln/RDuYv3osRQRhrZgcVATApwFT8vwdFvwT9re/ 32Hn4YMSO6HXkT+T+V8IGGMA1g92FBdmv8FsSJHmOJnO+ZryrJ1a6K+QhgycVMkRpEPy fPOA== X-Gm-Message-State: AOAM533O1c1tw+D/NrJ7yLBpIs78tVh6dqiVN28etBGGKab0PHdDb0/L iTcdiQCzS9FUwvZ2PMghdb4E80FgUObcjrkh3w/+BaVBaGsUCqhddoQkqpGWtjQ1v8zOroZV4ID YS+L+21i7cr0MepfOScfKZhnY X-Received: by 2002:a05:6214:c83:b0:441:51c7:9dc9 with SMTP id r3-20020a0562140c8300b0044151c79dc9mr1032427qvr.83.1649891998739; Wed, 13 Apr 2022 16:19:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK9G/2dn/UjZoKpRBN8/k1+sDOKT3FCsijjvf4/H/VFtzXaH6mAb5/vczmxNrXcN0x6fTE6A== X-Received: by 2002:a05:6214:c83:b0:441:51c7:9dc9 with SMTP id r3-20020a0562140c8300b0044151c79dc9mr1032419qvr.83.1649891998552; Wed, 13 Apr 2022 16:19:58 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:19:58 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 01/18] objtool: Enable unreachable warnings for CLANG LTO Date: Wed, 13 Apr 2022 16:19:36 -0700 Message-Id: <7b12df54bceeb0761fe9fc8269ea0c00501214a9.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With IBT support in, objtool is now fully capable of following vmlinux code flow in LTO mode. Start reporting unreachable warnings for Clang LTO as well. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 9717e6f6fb31..33c1ed581522 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -231,7 +231,7 @@ objtool_args =3D \ $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 20f44504a644..9361a1ef02c9 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -140,7 +140,7 @@ objtool_link() if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt=3D"${objtoolopt} --no-fp" fi - if is_enabled CONFIG_GCOV_KERNEL || is_enabled CONFIG_LTO_CLANG; then + if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt=3D"${objtoolopt} --no-unreachable" fi if is_enabled CONFIG_RETPOLINE; then --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F4DFC4332F for ; Wed, 13 Apr 2022 23:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239247AbiDMXWg (ORCPT ); Wed, 13 Apr 2022 19:22:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239045AbiDMXWZ (ORCPT ); Wed, 13 Apr 2022 19:22:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8A8623BC5 for ; Wed, 13 Apr 2022 16:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892002; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=442epl1h4yre5UcCgCdD+uGW52QoSWlok9Dl9A8mhpY=; b=EcXZvyxV4rj0nbLNQLuJ/UaVhQeIsP/vFat6dmPZGPpZ95GRpAKU4gtcP09jjSIRAcH8rm nsLqcwS/fqdnRWC0jki9QYHa2rW8wXjN2b8chpMk3CZZde6m0wvIiwWNOcUAo1uClqkiw7 CO9YdlhwUuszF+FWB0+SnYxJuRdisuA= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-498-NuYlwR1aNVKhDnrzPkU10A-1; Wed, 13 Apr 2022 19:20:01 -0400 X-MC-Unique: NuYlwR1aNVKhDnrzPkU10A-1 Received: by mail-qk1-f198.google.com with SMTP id bp31-20020a05620a459f00b00699fabcc554so2155404qkb.12 for ; Wed, 13 Apr 2022 16:20:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=442epl1h4yre5UcCgCdD+uGW52QoSWlok9Dl9A8mhpY=; b=tgg14FLq+hWN+eclUaux1NGcx4yN0mT8SX9XA0M6D+IcvPxhDOVKFe1BMjGkZtE+2I BkBJJwz5I4sdxAVDKF2AXnh+wEujjpax+gcYmzeb6mqT0eZyZJBic/xj6QLesRCOmbwu 6tFVnDkZSjYzYwcwGx8FwAXuyzxTsGgeEY9B2zZaKaaRgXRoGnr5nskJ/aDDw6YgxjU8 HIzNOcMnqFZghm/aUYzzxEdvhiqTdMkxyUoGxlnnWcLVLiIQjEnm+SsGo95YfXBdBq3+ K9o4ehLjbf2/23NZ+bVfS1gMMxvwSdcB1iqtCfxggWq4MUafDRtBQUko9UpB/EtpdzMS KcZQ== X-Gm-Message-State: AOAM532S1RRy4MuGRbwGVBVrVP5tcn3L00eU2Uazrwx2/CCbA8uAXoAo w7u5AIpfJtqdbSSC5sNU/bC9nwmvzsQ8NI0gxcpBl9wpsOZgrD1H0Ml4sv13dAUwU0mIpdqT2Ni 7pquelQC7PGJzVnDo+TuNXR21 X-Received: by 2002:a05:620a:1906:b0:67b:3ac1:8f72 with SMTP id bj6-20020a05620a190600b0067b3ac18f72mr8605945qkb.478.1649892000370; Wed, 13 Apr 2022 16:20:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVjaX8Z+d6CpU3KR7d7sRB46cwStUMLaVCHg9wMRz1XpHcd0PgUrCUc2AXRS7im+ErFl3HZw== X-Received: by 2002:a05:620a:1906:b0:67b:3ac1:8f72 with SMTP id bj6-20020a05620a190600b0067b3ac18f72mr8605933qkb.478.1649892000134; Wed, 13 Apr 2022 16:20:00 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:19:59 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 02/18] objtool: Support data symbol printing Date: Wed, 13 Apr 2022 16:19:37 -0700 Message-Id: <097057f88605aa67b0e3ec573fcf394ae7ac4d6f.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For data relocations to missing ENDBR, it will be useful in some cases to print the data symbol + offset. Add support for that. Signed-off-by: Josh Poimboeuf Suggested-by: Nick Desaulniers --- tools/objtool/include/objtool/warn.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index 802cfda0a6f6..dab0dda7c617 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -17,16 +17,19 @@ extern const char *objname; =20 static inline char *offstr(struct section *sec, unsigned long offset) { - struct symbol *func; - char *name, *str; + bool is_text =3D (sec->sh.sh_flags & SHF_EXECINSTR); + struct symbol *sym =3D NULL; unsigned long name_off; + char *name, *str; + + if (is_text) + sym =3D find_func_containing(sec, offset); + if (!sym) + sym =3D find_symbol_containing(sec, offset); =20 - func =3D find_func_containing(sec, offset); - if (!func) - func =3D find_symbol_containing(sec, offset); - if (func) { - name =3D func->name; - name_off =3D offset - func->offset; + if (sym) { + name =3D sym->name; + name_off =3D offset - sym->offset; } else { name =3D sec->name; name_off =3D offset; @@ -34,8 +37,8 @@ static inline char *offstr(struct section *sec, unsigned = long offset) =20 str =3D malloc(strlen(name) + 20); =20 - if (func) - sprintf(str, "%s()+0x%lx", name, name_off); + if (sym) + sprintf(str, "%s%s+0x%lx", name, is_text ? "()" : "", name_off); else sprintf(str, "%s+0x%lx", name, name_off); =20 --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEC65C433EF for ; Wed, 13 Apr 2022 23:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239220AbiDMXWs (ORCPT ); Wed, 13 Apr 2022 19:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239158AbiDMXW0 (ORCPT ); Wed, 13 Apr 2022 19:22:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7079D23BDD for ; Wed, 13 Apr 2022 16:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892003; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BGrvBgwYKVcZxNjPAVz0wV8tSGZLIzNr8FbkF5Q7c6c=; b=fUUp0c8QjaDU3dfvu3fJh3oyW3x647NxRR7CEOG/rU7Hcirdl6USwFFtoJjYHtTAexSIx5 SHGenS1tLBnGBDninq7G/DRkbQ1mRSjj7H6XAxcfJAXfgka9GOdZdTn9aF3ws27gi4w3Ml QFpE8G5dhwAaN2HK8zAut/DA0Sxgm7A= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-265-0-IDmroPP7iqebaYRhogRQ-1; Wed, 13 Apr 2022 19:20:02 -0400 X-MC-Unique: 0-IDmroPP7iqebaYRhogRQ-1 Received: by mail-qt1-f198.google.com with SMTP id m20-20020a05622a119400b002ef68184e7fso2219907qtk.15 for ; Wed, 13 Apr 2022 16:20:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BGrvBgwYKVcZxNjPAVz0wV8tSGZLIzNr8FbkF5Q7c6c=; b=OanuRGHlgWkd3XGS6ZBv0JUkp93/erllfnCKUWqqEjpqWxY/+PXEOIfL/kO1vHJ9dN s5z76+ch4x2RLv2/7zOmudNFfYn/qtwOofc81sgwO4PxMAVQd5bznMl3B3tf9a0mSOYX xtEhFyOhBjWhNF929oY1L760Sp1u51VLrRluGSGjc6hYdC5+VnY9YrYJvCsEhvDEZfi7 J2iPm8H7T3zdiDcVdXkMT2Ov02RL/YbssnMDR5/lsLH/fpHpxdJWQdMSgq8uYBum6B6A AixSdmQKoVuO22QKJ4rtWc/OYk3YAP7mBTj0cjBe5mGWzjKmP4odZr64iQ3SLqPRRfhU PvGw== X-Gm-Message-State: AOAM531H3792tPA6/ooYDAN5l1MN11k/O3zbefOlEhSmmfayorMcMkZx z5y5mW99WmUGMp2yI273Jr4b/RbVGB5ECEet0crXlXDgMnAtSwPsfsse0jhUlT/W5hBHjm+Hcau Sqa0p+4ORCtrJOlA3af7DsQZK X-Received: by 2002:ac8:7088:0:b0:2f1:89a6:4001 with SMTP id y8-20020ac87088000000b002f189a64001mr5341794qto.588.1649892001938; Wed, 13 Apr 2022 16:20:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOD2TTAOnlx406Slej/kYMmagHy+ojVopPnLeDEqApBQ6pl6+0R1x0MQwx/Ef8VLuk5KwadA== X-Received: by 2002:ac8:7088:0:b0:2f1:89a6:4001 with SMTP id y8-20020ac87088000000b002f189a64001mr5341782qto.588.1649892001687; Wed, 13 Apr 2022 16:20:01 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:01 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes , Nick Desaulniers Subject: [PATCH 03/18] objtool: Add sec+offset to warnings Date: Wed, 13 Apr 2022 16:19:38 -0700 Message-Id: <76e1ed8e27b6fb3ed584004ad3fb79a95914b7e6.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Change this: vmlinux.o: warning: objtool: fixup_exception()+0x2d1: unreachable instruc= tion to this: vmlinux.o: warning: objtool: fixup_exception()+0x2d1: .text+0x76c51: unre= achable instruction It's noisier, but it makes our lives considerably easier. Make this new 'verbose' mode optional, which will come in handy soon. Suggested-by: Nick Desaulniers Signed-off-by: Josh Poimboeuf --- tools/objtool/include/objtool/warn.h | 39 +++++++++++++--------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index dab0dda7c617..a4c6b52a58c9 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -15,12 +15,13 @@ =20 extern const char *objname; =20 -static inline char *offstr(struct section *sec, unsigned long offset) +static inline char *offstr(struct section *sec, unsigned long offset, + bool verbose) { bool is_text =3D (sec->sh.sh_flags & SHF_EXECINSTR); struct symbol *sym =3D NULL; - unsigned long name_off; - char *name, *str; + char *str; + int len; =20 if (is_text) sym =3D find_func_containing(sec, offset); @@ -28,20 +29,16 @@ static inline char *offstr(struct section *sec, unsigne= d long offset) sym =3D find_symbol_containing(sec, offset); =20 if (sym) { - name =3D sym->name; - name_off =3D offset - sym->offset; + str =3D malloc(strlen(sym->name) + strlen(sec->name) + 40); + len =3D sprintf(str, "%s%s+0x%lx", + sym->name, is_text ? "()" : "", offset - sym->offset); + if (verbose) + sprintf(str+len, ": %s+0x%lx", sec->name, offset); } else { - name =3D sec->name; - name_off =3D offset; + str =3D malloc(strlen(sec->name) + 20); + sprintf(str, "%s+0x%lx", sec->name, offset); } =20 - str =3D malloc(strlen(name) + 20); - - if (sym) - sprintf(str, "%s%s+0x%lx", name, is_text ? "()" : "", name_off); - else - sprintf(str, "%s+0x%lx", name, name_off); - return str; } =20 @@ -52,17 +49,17 @@ static inline char *offstr(struct section *sec, unsigne= d long offset) =20 #define WARN_FUNC(format, sec, offset, ...) \ ({ \ - char *_str =3D offstr(sec, offset); \ + char *_str =3D offstr(sec, offset, true); \ WARN("%s: " format, _str, ##__VA_ARGS__); \ free(_str); \ }) =20 -#define BT_FUNC(format, insn, ...) \ -({ \ - struct instruction *_insn =3D (insn); \ - char *_str =3D offstr(_insn->sec, _insn->offset); \ - WARN(" %s: " format, _str, ##__VA_ARGS__); \ - free(_str); \ +#define BT_FUNC(format, insn, ...) \ +({ \ + struct instruction *_insn =3D (insn); \ + char *_str =3D offstr(_insn->sec, _insn->offset, true); \ + WARN(" %s: " format, _str, ##__VA_ARGS__); \ + free(_str); \ }) =20 #define WARN_ELF(format, ...) \ --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A843FC433F5 for ; Wed, 13 Apr 2022 23:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239260AbiDMXXC (ORCPT ); Wed, 13 Apr 2022 19:23:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239168AbiDMXW3 (ORCPT ); Wed, 13 Apr 2022 19:22:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3822323BE5 for ; Wed, 13 Apr 2022 16:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892005; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BHuuVJWlvrxXx0mO6xbXx/8ozzJANVHdMftQcW5g5Us=; b=gmab3WDNDduWfRfR2dVDOXgpmATKzm6yEuTmaR87h6OUk+AUvcYkPJvfpfAbC0UPSbxi68 8vpzn9C8HEohf3KyDuQ9tY2BZeVhkT/4TNujqQuAcxLbTgHlYulejr0kn7Rhzy+7HbrP/o EWeAQnSbGT/tYUJugUMKBKIkYd9PZKA= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-484-XAXNL7tBOO2xxW2qSFGheQ-1; Wed, 13 Apr 2022 19:20:04 -0400 X-MC-Unique: XAXNL7tBOO2xxW2qSFGheQ-1 Received: by mail-qt1-f197.google.com with SMTP id z3-20020ac86b83000000b002ed0f18c23cso2214517qts.17 for ; Wed, 13 Apr 2022 16:20:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BHuuVJWlvrxXx0mO6xbXx/8ozzJANVHdMftQcW5g5Us=; b=n8ixq/By2sHIJYv4qKop9f9F1YXpmDqMqtGqeDf1zRprAQS5rMWfgI4wYrDzhhF0vd fPOwHmeLQHPEH/RAb9Px2i4IrO3sZHDL1rimEH/YTfCvVgrJz34mtqCLEdtEo6E+FjJJ 5Xw5Qzuk1BTGHKFgjRcLih1bsXtKEL2T0sNoGw930ECqpSdB8d+kHS4Gk3eaNIpEmFui c54db2gwtoZE+YauE1KJv+grdCphaV5Zbnr6+s80FfKcJNE7jzSCdwEuwn64/MMlpn6B g3M7w+xjDeh0DfSLuEhc+eIUCZ8SLhKKQlGi05nhtfoOzdcu4UJc7IggpJ48yiNEE/pi Q5Ag== X-Gm-Message-State: AOAM532Pf/4aXx+bswg3LYo+B8VsyGcB0D3U5bSkKDQS5Gcdxvf40Ryk EVhv/WTZ8d47BMCr8ckLJcrlzDvaPTm6blNZf+78O8tqSuXab870xFFKi9fKKgYGNWzVmqgtgWa hXRhNtSt+RcI1o2nRZ31mSzCE X-Received: by 2002:a05:6214:300d:b0:444:4ada:a471 with SMTP id ke13-20020a056214300d00b004444adaa471mr1037216qvb.93.1649892003431; Wed, 13 Apr 2022 16:20:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWFG0Q4OCZ9/S2OUyvhDtsAEUq0kQxxzhgvu7klVXQ4+McpzuRKD53TLydwbrR+krLLHmBPQ== X-Received: by 2002:a05:6214:300d:b0:444:4ada:a471 with SMTP id ke13-20020a056214300d00b004444adaa471mr1037201qvb.93.1649892003185; Wed, 13 Apr 2022 16:20:03 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:02 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 04/18] objtool: Print data address for "!ENDBR" data warnings Date: Wed, 13 Apr 2022 16:19:39 -0700 Message-Id: <8208fa7edf2dc576e8f9bcf24396b128f59bdfe9.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When a "!ENDBR" warning is reported for a data section, objtool just prints the text address of the relocation target twice, without giving any clues about the location of the original data reference: vmlinux.o: warning: objtool: dcbnl_netdevice_event()+0x0: .text+0xb64680:= data relocation to !ENDBR: dcbnl_netdevice_event+0x0 Instead, print the address of the data reference, in addition to the address of the relocation target. vmlinux.o: warning: objtool: dcbnl_nb+0x0: .data..read_mostly+0xe260: dat= a relocation to !ENDBR: dcbnl_netdevice_event+0x0 Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5bd3aa815d51..7a1a02dacb77 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3825,11 +3825,8 @@ static int validate_ibt(struct objtool_file *file) struct instruction *dest; =20 dest =3D validate_ibt_reloc(file, reloc); - if (is_data && dest && !dest->noendbr) { - warn_noendbr("data ", reloc->sym->sec, - reloc->sym->offset + reloc->addend, - dest); - } + if (is_data && dest && !dest->noendbr) + warn_noendbr("data ", sec, reloc->offset, dest); } } =20 --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CDDAC433EF for ; Wed, 13 Apr 2022 23:20:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239302AbiDMXW5 (ORCPT ); Wed, 13 Apr 2022 19:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239198AbiDMXWd (ORCPT ); Wed, 13 Apr 2022 19:22:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 280D02B27C for ; Wed, 13 Apr 2022 16:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892007; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=24h2UVDbRHHVLlC2Pwg8j1khR625cr4JBFHOIM2d6fU=; b=SVx6tXpXAviF25xAbjOlP01Cr1jab8gNbKx4a3U+c3PuaWn2AV86tEQDOHTmw0STopsX7h DodlmUQIDPPSuFLGLe2e/7ZqzriWwGW6ef7jXhwuynoN3R0jXNFHhae+oi4Z2jLjVgV3lr cKH3/lsprSRKzb2n2PVW94GYKtPnGco= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-499-CRRz5NAoNNmPhrbepL1uQg-1; Wed, 13 Apr 2022 19:20:05 -0400 X-MC-Unique: CRRz5NAoNNmPhrbepL1uQg-1 Received: by mail-qv1-f72.google.com with SMTP id dd5-20020ad45805000000b004461b16d4caso1742036qvb.16 for ; Wed, 13 Apr 2022 16:20:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=24h2UVDbRHHVLlC2Pwg8j1khR625cr4JBFHOIM2d6fU=; b=3aqBRxLtktGkDUlMBCcDDF+ElaMaCILqCBYWuzH72jxVRgDEVAo1YnxVuOi66iktsE /TWXdJ+G6FRjBTE0R6v03c2d6HKBY6X2fTAV+Q8Ein8xJQM/fcfGWbid/TMzkiWV2csU 898AF9tTeEAMsvvDg9hq3zpSbYEtA2SfeyO0Z73tDA9jgaZ2FVltSAuw8KSRq92WsGfT LqJ/S1L1DNLpnMlFfVa/5FqMSai2cCMZdJqohT6AjavPkbA07mUe+igKMzqnZIZhSr7O RSQPeLHhWjUw/A6wmT40WCsrMjcZ4Tezl6zytjl/BfA1EuFg5XJ3yeUfdYvWhYNTgTzH PGGQ== X-Gm-Message-State: AOAM532ZyMt8dRPWqNZcW4GNxXVo/fPvt9UseP+YXpzyfwXDhnvWXEfk Pxog7sdOBgMua0sLtIkRu93JJMyz64Gosa8GjAqED7wJ2Yda/5JxAckDIbY6D1lpFHObsKtgD/+ 4mbR8NseXiGF2yf11QOrLio1A X-Received: by 2002:a05:620a:40ca:b0:69c:59d7:9d06 with SMTP id g10-20020a05620a40ca00b0069c59d79d06mr3516482qko.0.1649892005096; Wed, 13 Apr 2022 16:20:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2yYZiDbxv+G1x1q/PriByATvG+RzT0FBcaPyy0T6nN5oKkjW9Z07oFx7eymFaduJSzROiqA== X-Received: by 2002:a05:620a:40ca:b0:69c:59d7:9d06 with SMTP id g10-20020a05620a40ca00b0069c59d79d06mr3516469qko.0.1649892004876; Wed, 13 Apr 2022 16:20:04 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:04 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 05/18] objtool: Use offstr() to print address of missing ENDBR Date: Wed, 13 Apr 2022 16:19:40 -0700 Message-Id: <28a9b87970329e70c59c575a240fb9390c2e24f9.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 7a1a02dacb77..b27c2ce5d79e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3219,9 +3219,8 @@ validate_ibt_reloc(struct objtool_file *file, struct = reloc *reloc) static void warn_noendbr(const char *msg, struct section *sec, unsigned lo= ng offset, struct instruction *dest) { - WARN_FUNC("%srelocation to !ENDBR: %s+0x%lx", sec, offset, msg, - dest->func ? dest->func->name : dest->sec->name, - dest->func ? dest->offset - dest->func->offset : dest->offset); + WARN_FUNC("%srelocation to !ENDBR: %s", sec, offset, msg, + offstr(dest->sec, dest->offset, false)); } =20 static void validate_ibt_dest(struct objtool_file *file, struct instructio= n *insn, --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F228C433EF for ; Wed, 13 Apr 2022 23:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239254AbiDMXWw (ORCPT ); Wed, 13 Apr 2022 19:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239217AbiDMXWd (ORCPT ); Wed, 13 Apr 2022 19:22:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E42CB326F2 for ; Wed, 13 Apr 2022 16:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892008; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=osWjVIWrfBrDOezJiYzosX0/AGt77HLN11DnBu9dxXM=; b=Qo7LHc/Oo/vb3MolYwnR9Z1eC8SPYAh6K1h0X4ocK+E8GYPQMusivWdDIKiFTIbDgPWO/h zs89m2oEZ45r6vDdKyUdPlt8aBHVREwwCdmJdHOELlD61phipfq1GU6RBW4Yvnh1AIGBK1 VuwhqjxV03vlYcPu9mfw8cpH4zUrhJE= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-523-n9XLawO1MTKk1a7m2TT0rg-1; Wed, 13 Apr 2022 19:20:07 -0400 X-MC-Unique: n9XLawO1MTKk1a7m2TT0rg-1 Received: by mail-qv1-f69.google.com with SMTP id m15-20020a0562141bcf00b00443ddcd8a0fso3003262qvc.12 for ; Wed, 13 Apr 2022 16:20:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=osWjVIWrfBrDOezJiYzosX0/AGt77HLN11DnBu9dxXM=; b=SJHDfNXiETuS/jx+uSKv1sK0OFPa5hbsw+uKKhAnuSfVxCdG9zhWNMZ0l7EyX69Iky yIBygzl4GXxx0kN8QhaubSAFWdtG56gO4Jcu5WVwaMGDc1aKJcNdWnmpGQiLqIaYi9x1 e/QU5NdQWKi3UxKgUQKgInSZGYGgnbPaewaOyg/qNlaUzq+2d44lOHde8zJRa/NK1750 6R7lWnI7BvCso1eXsI7OsDgdP04dbh9i489JxGLJ9LxpfLPpIUhehp6sMZdECwi0j4u3 jnXmJBhaAI5Gw7/fEUD8g1NuY7s0BzyKiBun6i2bA0o6QxMipTv6VF5OPqhx/2HpWDBC 8ELA== X-Gm-Message-State: AOAM531FEKV7sxk5IIepnSppbCy84hlNfqHUg98X2ErecPBptAhM0dte U8OXuzIIbk5GClDvKGIUgq+uXZ7cQ7QpVC0kNqvJq9a0yQz/IDQSArTVhRW4EuM0rZtzMZ8hSp7 G1fhWGGlhMEex94TBEzlnvNZH X-Received: by 2002:a37:a50:0:b0:69c:7129:12da with SMTP id 77-20020a370a50000000b0069c712912damr361663qkk.90.1649892006786; Wed, 13 Apr 2022 16:20:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvuV8WO9SUCdKFN4q16meRMbgMj70DgGoWRdHrkbeeTu6mzBPy9DekbViM5M8o/ql60amcUA== X-Received: by 2002:a37:a50:0:b0:69c:7129:12da with SMTP id 77-20020a370a50000000b0069c712912damr361648qkk.90.1649892006488; Wed, 13 Apr 2022 16:20:06 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:05 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 06/18] libsubcmd: Fix OPTION_GROUP sorting Date: Wed, 13 Apr 2022 16:19:41 -0700 Message-Id: <40da04924ddb81a5acc3f9376bdcb6d2a91d36fa.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The OPTION_GROUP option type is a way of grouping certain options together in the printed usage text. It happens to be completely broken, thanks to the fact that the subcmd option sorting just sorts everything, without regard for grouping. Luckily, nobody uses this option anyway, though that will change shortly. Fix it by sorting each group individually. Signed-off-by: Josh Poimboeuf --- tools/lib/subcmd/parse-options.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-opti= ons.c index 39ebf6192016..9fa75943f2ed 100644 --- a/tools/lib/subcmd/parse-options.c +++ b/tools/lib/subcmd/parse-options.c @@ -806,9 +806,9 @@ static int option__cmp(const void *va, const void *vb) =20 static struct option *options__order(const struct option *opts) { - int nr_opts =3D 0, len; + int nr_opts =3D 0, nr_group =3D 0, len; const struct option *o =3D opts; - struct option *ordered; + struct option *opt, *ordered, *group; =20 for (o =3D opts; o->type !=3D OPTION_END; o++) ++nr_opts; @@ -819,7 +819,18 @@ static struct option *options__order(const struct opti= on *opts) goto out; memcpy(ordered, opts, len); =20 - qsort(ordered, nr_opts, sizeof(*o), option__cmp); + /* sort each option group individually */ + for (opt =3D group =3D ordered; opt->type !=3D OPTION_END; opt++) { + if (opt->type =3D=3D OPTION_GROUP) { + qsort(group, nr_group, sizeof(*opt), option__cmp); + group =3D opt + 1; + nr_group =3D 0; + continue; + } + nr_group++; + } + qsort(group, nr_group, sizeof(*opt), option__cmp); + out: return ordered; } --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 606E9C433F5 for ; Wed, 13 Apr 2022 23:22:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239432AbiDMXY1 (ORCPT ); Wed, 13 Apr 2022 19:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239237AbiDMXWf (ORCPT ); Wed, 13 Apr 2022 19:22:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C59D3A5D1 for ; Wed, 13 Apr 2022 16:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892010; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ychhaRzz2uHI/l+EWy0iFhYfdo18db/Qi9v32WYip94=; b=GzOQS1LvYqnLbc+mt6hj3tLJh9zWOeV7YNhMBLnJ/OwmQvlpibPzsIOCqVgeimwWoIS7vP lwlugJHXZKwaBn/5p9tiZsTezpZsPzQSa+XbXQjEZv6khaMDrCg7j4ZKU01BVXDKi+Qg04 urSDg/HQ6kgcLLJT/ywN3T7w31yWvi8= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-250-DVus8TnFMeeqAwHXQByseQ-1; Wed, 13 Apr 2022 19:20:09 -0400 X-MC-Unique: DVus8TnFMeeqAwHXQByseQ-1 Received: by mail-qk1-f199.google.com with SMTP id q5-20020a05620a0d8500b004738c1b48beso2165991qkl.7 for ; Wed, 13 Apr 2022 16:20:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ychhaRzz2uHI/l+EWy0iFhYfdo18db/Qi9v32WYip94=; b=UPflxhrZjHWyjq1M7uxZN54ZuKsC+fOISBpVPZY3xrSWIj41jcs1h7oMHzxlzbFSy7 4xGvlRm5W4BWDHCZW/iRbxHccBkm5944hA1R5fsGg87cP6T73paybFpe7orWvEZpjriG qqf5ypeD9o4PcjqXellmuykvrze+JIFMHsNmhvBd4JJ1y46mrTXHOqdyk3ZSXJQjn8EJ 53Da4vqXjCoVK/OneLAQE1YYJvrZ43aqh/bRs7XKhl85z4K7z3OSfOWl69af0PCQFLFv eS34PavjscD36UqemT+Vyea/dbc5k+eCOQ4QJGxBEfr22/dmCImhWGcYXvYvYjn1cRIN X7qg== X-Gm-Message-State: AOAM531I0NcEVmv+yzvdHk2/FTCiMZEywtCEB4qoHuC1fvXb00FGUtFr i9P2iqg6GJuj5Ggkw5VuFwCwcFZ9alnYQ+QF7OezgV5Fcbwo1snih5YFUMjz63sE+T7Oa0xzjL2 sc0HQMbuj6qyPjwC+iwq+chOZ X-Received: by 2002:a05:6214:21ad:b0:444:3de0:148c with SMTP id t13-20020a05621421ad00b004443de0148cmr1048700qvc.119.1649892008659; Wed, 13 Apr 2022 16:20:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjgHCMnYGzKJl9ADv96L9Xgz0T1Mo2xZEQCVbid6X7kYJ/KAendvokv9sGhAiGbhln4zYrTg== X-Received: by 2002:a05:6214:21ad:b0:444:3de0:148c with SMTP id t13-20020a05621421ad00b004443de0148cmr1048679qvc.119.1649892008340; Wed, 13 Apr 2022 16:20:08 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:07 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 07/18] objtool: Reorganize cmdline options Date: Wed, 13 Apr 2022 16:19:42 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Split the existing options into two groups: actions, which actually do something; and options, which modify the actions in some way. Also there's no need to have short flags for all the non-action options. Reserve short flags for the more important actions. While at it: - change a few of the short flags to be more intuitive - make option descriptions more consistently descriptive - sort options in the source like they are when printed - move options to a global struct Signed-off-by: Josh Poimboeuf --- scripts/Makefile.build | 10 ++-- scripts/link-vmlinux.sh | 30 +++++++----- tools/objtool/arch/x86/decode.c | 2 +- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/builtin-check.c | 40 ++++++++-------- tools/objtool/check.c | 62 ++++++++++++------------- tools/objtool/elf.c | 8 ++-- tools/objtool/include/objtool/builtin.h | 26 +++++++++-- tools/objtool/objtool.c | 6 +-- 9 files changed, 108 insertions(+), 78 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 33c1ed581522..dd9d582808d6 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -228,14 +228,14 @@ objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ - $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ + $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ + $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ - $(if $(CONFIG_SLS), --sls) + $(if $(part-of-module), --module) \ + $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) =20 cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep =3D $(if $(objtool-enabled), { echo ; echo '$@: $$(wild= card $(objtool))' ; } >> $(dot-target).cmd) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 9361a1ef02c9..c6e9fef61b11 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -117,8 +117,6 @@ objtool_link() objtoolcmd=3D"orc generate" fi =20 - objtoolopt=3D"${objtoolopt} --lto" - if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt=3D"${objtoolopt} --ibt" fi @@ -126,6 +124,8 @@ objtool_link() if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then objtoolopt=3D"${objtoolopt} --mcount" fi + + objtoolopt=3D"${objtoolopt} --lto" fi =20 if is_enabled CONFIG_VMLINUX_VALIDATION; then @@ -133,25 +133,33 @@ objtool_link() fi =20 if [ -n "${objtoolopt}" ]; then + if [ -z "${objtoolcmd}" ]; then objtoolcmd=3D"check" fi - objtoolopt=3D"${objtoolopt} --vmlinux" - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt=3D"${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then - objtoolopt=3D"${objtoolopt} --no-unreachable" - fi + if is_enabled CONFIG_RETPOLINE; then objtoolopt=3D"${objtoolopt} --retpoline" fi + + if is_enabled CONFIG_SLS; then + objtoolopt=3D"${objtoolopt} --sls" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt=3D"${objtoolopt} --uaccess" fi - if is_enabled CONFIG_SLS; then - objtoolopt=3D"${objtoolopt} --sls" + + if ! is_enabled CONFIG_FRAME_POINTER; then + objtoolopt=3D"${objtoolopt} --no-fp" fi + + if is_enabled CONFIG_GCOV_KERNEL; then + objtoolopt=3D"${objtoolopt} --no-unreachable" + fi + + objtoolopt=3D"${objtoolopt} --vmlinux" + info OBJTOOL ${1} tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} fi diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 943cb41cddf7..8b990a52aada 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -581,7 +581,7 @@ int arch_decode_instruction(struct objtool_file *file, = const struct section *sec break; =20 case 0xc7: /* mov imm, r/m */ - if (!noinstr) + if (!opts.noinstr) break; =20 if (insn.length =3D=3D 3+4+4 && !strncmp(sec->name, ".init.text", 10)) { diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index e707d9bcd161..7c97b7391279 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -20,7 +20,7 @@ void arch_handle_alternative(unsigned short feature, stru= ct special_alt *alt) * find paths that see the STAC but take the NOP instead of * CLAC and the other way around. */ - if (uaccess) + if (opts.uaccess) alt->skip_orig =3D true; else alt->skip_alt =3D true; diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index fc6975ab8b06..4f4a087720b3 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -19,12 +19,10 @@ #include #include =20 -bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; +struct opts opts; =20 static const char * const check_usage[] =3D { - "objtool check [] file.o", + "objtool check [] file.o", NULL, }; =20 @@ -34,21 +32,25 @@ static const char * const env_usage[] =3D { }; =20 const struct option check_options[] =3D { - OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"), - OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable in= struction' warnings"), - OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions= "), - OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of= a kernel module"), - OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"), - OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"), - OPT_BOOLEAN('s', "stats", &stats, "print statistics"), - OPT_BOOLEAN(0, "lto", <o, "whole-archive like runs"), - OPT_BOOLEAN('n', "noinstr", &noinstr, "noinstr validation for vmlinux.o"), - OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"), - OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"), - OPT_BOOLEAN('B', "backup", &backup, "create .orig files before modificati= on"), - OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"), - OPT_BOOLEAN(0, "dry-run", &dryrun, "don't write the modifications"), - OPT_BOOLEAN(0, "ibt", &ibt, "validate ENDBR placement"), + OPT_GROUP("Actions:"), + OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), + OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), + OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), + OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), + OPT_BOOLEAN('S', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), + OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), + + OPT_GROUP("Options:"), + OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"), + OPT_BOOLEAN(0, "backup", &opts.backup, "create .orig files before modific= ation"), + OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), + OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"), + OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module= "), + OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"), + OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable= instruction' warnings"), + OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), + OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"), + OPT_END(), }; =20 diff --git a/tools/objtool/check.c b/tools/objtool/check.c index b27c2ce5d79e..5059c097c563 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -274,7 +274,7 @@ static void init_insn_state(struct insn_state *state, s= truct section *sec) * not correctly determine insn->call_dest->sec (external symbols do * not have a section). */ - if (vmlinux && noinstr && sec) + if (opts.vmlinux && opts.noinstr && sec) state->noinstr =3D sec->noinstr; } =20 @@ -340,7 +340,7 @@ static void *cfi_hash_alloc(unsigned long size) if (cfi_hash =3D=3D (void *)-1L) { WARN("mmap fail cfi_hash"); cfi_hash =3D NULL; - } else if (stats) { + } else if (opts.stats) { printf("cfi_bits: %d\n", cfi_bits); } =20 @@ -435,7 +435,7 @@ static int decode_instructions(struct objtool_file *fil= e) } } =20 - if (stats) + if (opts.stats) printf("nr_insns: %lu\n", nr_insns); =20 return 0; @@ -498,7 +498,7 @@ static int init_pv_ops(struct objtool_file *file) struct symbol *sym; int idx, nr; =20 - if (!noinstr) + if (!opts.noinstr) return 0; =20 file->pv_ops =3D NULL; @@ -669,7 +669,7 @@ static int create_static_call_sections(struct objtool_f= ile *file) =20 key_sym =3D find_symbol_by_name(file->elf, tmp); if (!key_sym) { - if (!module) { + if (!opts.module) { WARN("static_call: can't find static_call_key symbol: %s", tmp); return -1; } @@ -762,7 +762,7 @@ static int create_ibt_endbr_seal_sections(struct objtoo= l_file *file) list_for_each_entry(insn, &file->endbr_list, call_node) idx++; =20 - if (stats) { + if (opts.stats) { printf("ibt: ENDBR at function start: %d\n", file->nr_endbr); printf("ibt: ENDBR inside functions: %d\n", file->nr_endbr_int); printf("ibt: superfluous ENDBR: %d\n", idx); @@ -1029,7 +1029,7 @@ static void add_uaccess_safe(struct objtool_file *fil= e) struct symbol *func; const char **name; =20 - if (!uaccess) + if (!opts.uaccess) return; =20 for (name =3D uaccess_safe_builtin; *name; name++) { @@ -1171,7 +1171,7 @@ static void annotate_call_site(struct objtool_file *f= ile, return; } =20 - if (mcount && sym->fentry) { + if (opts.mcount && sym->fentry) { if (sibling) WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset); =20 @@ -1257,7 +1257,7 @@ static bool is_first_func_insn(struct objtool_file *f= ile, struct instruction *in if (insn->offset =3D=3D insn->func->offset) return true; =20 - if (ibt) { + if (opts.ibt) { struct instruction *prev =3D prev_insn_same_sym(file, insn); =20 if (prev && prev->type =3D=3D INSN_ENDBR && @@ -1700,7 +1700,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) free(special_alt); } =20 - if (stats) { + if (opts.stats) { printf("jl\\\tNOP\tJMP\n"); printf("short:\t%ld\t%ld\n", file->jl_nop_short, file->jl_short); printf("long:\t%ld\t%ld\n", file->jl_nop_long, file->jl_long); @@ -1946,7 +1946,7 @@ static int read_unwind_hints(struct objtool_file *fil= e) =20 insn->hint =3D true; =20 - if (ibt && hint->type =3D=3D UNWIND_HINT_TYPE_REGS_PARTIAL) { + if (opts.ibt && hint->type =3D=3D UNWIND_HINT_TYPE_REGS_PARTIAL) { struct symbol *sym =3D find_symbol_by_offset(insn->sec, insn->offset); =20 if (sym && sym->bind =3D=3D STB_GLOBAL && @@ -2807,7 +2807,7 @@ static int update_cfi_state(struct instruction *insn, } =20 /* detect when asm code uses rbp as a scratch register */ - if (!no_fp && insn->func && op->src.reg =3D=3D CFI_BP && + if (!opts.no_fp && insn->func && op->src.reg =3D=3D CFI_BP && cfa->base !=3D CFI_BP) cfi->bp_scratch =3D true; break; @@ -3364,7 +3364,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, =20 ret =3D validate_branch(file, func, alt->insn, state); if (ret) { - if (backtrace) + if (opts.backtrace) BT_FUNC("(alt)", insn); return ret; } @@ -3380,7 +3380,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, switch (insn->type) { =20 case INSN_RETURN: - if (sls && !insn->retpoline_safe && + if (opts.sls && !insn->retpoline_safe && next_insn && next_insn->type !=3D INSN_TRAP) { WARN_FUNC("missing int3 after ret", insn->sec, insn->offset); @@ -3393,7 +3393,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (ret) return ret; =20 - if (!no_fp && func && !is_fentry_call(insn) && + if (!opts.no_fp && func && !is_fentry_call(insn) && !has_valid_stack_frame(&state)) { WARN_FUNC("call without frame pointer save/setup", sec, insn->offset); @@ -3416,7 +3416,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, ret =3D validate_branch(file, func, insn->jump_dest, state); if (ret) { - if (backtrace) + if (opts.backtrace) BT_FUNC("(branch)", insn); return ret; } @@ -3428,7 +3428,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, break; =20 case INSN_JUMP_DYNAMIC: - if (sls && !insn->retpoline_safe && + if (opts.sls && !insn->retpoline_safe && next_insn && next_insn->type !=3D INSN_TRAP) { WARN_FUNC("missing int3 after indirect jump", insn->sec, insn->offset); @@ -3500,7 +3500,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, break; } =20 - if (ibt) + if (opts.ibt) validate_ibt_insn(file, insn); =20 if (insn->dead_end) @@ -3542,7 +3542,7 @@ static int validate_unwind_hints(struct objtool_file = *file, struct section *sec) while (&insn->list !=3D &file->insn_list && (!sec || insn->sec =3D=3D sec= )) { if (insn->hint && !insn->visited && !insn->ignore) { ret =3D validate_branch(file, insn->func, insn, state); - if (ret && backtrace) + if (ret && opts.backtrace) BT_FUNC("<=3D=3D=3D (hint)", insn); warnings +=3D ret; } @@ -3572,7 +3572,7 @@ static int validate_retpoline(struct objtool_file *fi= le) * loaded late, they very much do need retpoline in their * .init.text */ - if (!strcmp(insn->sec->name, ".init.text") && !module) + if (!strcmp(insn->sec->name, ".init.text") && !opts.module) continue; =20 WARN_FUNC("indirect %s found in RETPOLINE build", @@ -3622,7 +3622,7 @@ static bool ignore_unreachable_insn(struct objtool_fi= le *file, struct instructio * In this case we'll find a piece of code (whole function) that is not * covered by a !section symbol. Ignore them. */ - if (!insn->func && lto) { + if (!insn->func && opts.lto) { int size =3D find_symbol_hole_containing(insn->sec, insn->offset); unsigned long end =3D insn->offset + size; =20 @@ -3729,7 +3729,7 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, state->uaccess =3D sym->uaccess_safe; =20 ret =3D validate_branch(file, insn->func, insn, *state); - if (ret && backtrace) + if (ret && opts.backtrace) BT_FUNC("<=3D=3D=3D (sym)", insn); return ret; } @@ -3854,12 +3854,12 @@ int check(struct objtool_file *file) { int ret, warnings =3D 0; =20 - if (lto && !(vmlinux || module)) { + if (opts.lto && !(opts.vmlinux || opts.module)) { fprintf(stderr, "--lto requires: --vmlinux or --module\n"); return 1; } =20 - if (ibt && !lto) { + if (opts.ibt && !opts.lto) { fprintf(stderr, "--ibt requires: --lto\n"); return 1; } @@ -3884,7 +3884,7 @@ int check(struct objtool_file *file) if (list_empty(&file->insn_list)) goto out; =20 - if (vmlinux && !lto) { + if (opts.vmlinux && !opts.lto) { ret =3D validate_vmlinux_functions(file); if (ret < 0) goto out; @@ -3893,7 +3893,7 @@ int check(struct objtool_file *file) goto out; } =20 - if (retpoline) { + if (opts.retpoline) { ret =3D validate_retpoline(file); if (ret < 0) return ret; @@ -3910,7 +3910,7 @@ int check(struct objtool_file *file) goto out; warnings +=3D ret; =20 - if (ibt) { + if (opts.ibt) { ret =3D validate_ibt(file); if (ret < 0) goto out; @@ -3929,28 +3929,28 @@ int check(struct objtool_file *file) goto out; warnings +=3D ret; =20 - if (retpoline) { + if (opts.retpoline) { ret =3D create_retpoline_sites_sections(file); if (ret < 0) goto out; warnings +=3D ret; } =20 - if (mcount) { + if (opts.mcount) { ret =3D create_mcount_loc_sections(file); if (ret < 0) goto out; warnings +=3D ret; } =20 - if (ibt) { + if (opts.ibt) { ret =3D create_ibt_endbr_seal_sections(file); if (ret < 0) goto out; warnings +=3D ret; } =20 - if (stats) { + if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); printf("nr_cfi: %ld\n", nr_cfi); printf("nr_cfi_reused: %ld\n", nr_cfi_reused); diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index d7b99a737496..f7b2ad27bb1c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -355,7 +355,7 @@ static int read_sections(struct elf *elf) elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); } =20 - if (stats) { + if (opts.stats) { printf("nr_sections: %lu\n", (unsigned long)sections_nr); printf("section_bits: %d\n", elf->section_bits); } @@ -475,7 +475,7 @@ static int read_symbols(struct elf *elf) elf_add_symbol(elf, sym); } =20 - if (stats) { + if (opts.stats) { printf("nr_symbols: %lu\n", (unsigned long)symbols_nr); printf("symbol_bits: %d\n", elf->symbol_bits); } @@ -700,7 +700,7 @@ static int read_relocs(struct elf *elf) tot_reloc +=3D nr_reloc; } =20 - if (stats) { + if (opts.stats) { printf("max_reloc: %lu\n", max_reloc); printf("tot_reloc: %lu\n", tot_reloc); printf("reloc_bits: %d\n", elf->reloc_bits); @@ -1079,7 +1079,7 @@ int elf_write(struct elf *elf) struct section *sec; Elf_Scn *s; =20 - if (dryrun) + if (opts.dryrun) return 0; =20 /* Update changed relocation sections and section headers: */ diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index c39dbfaef6dc..87c1a7351e3c 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -8,9 +8,29 @@ #include =20 extern const struct option check_options[]; -extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, = stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; + +struct opts { + /* actions: */ + bool ibt; + bool mcount; + bool noinstr; + bool retpoline; + bool sls; + bool uaccess; + + /* options: */ + bool backtrace; + bool backup; + bool dryrun; + bool lto; + bool module; + bool no_fp; + bool no_unreachable; + bool stats; + bool vmlinux; +}; + +extern struct opts opts; =20 extern int cmd_parse_options(int argc, const char **argv, const char * con= st usage[]); =20 diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 843ff3c2f28e..a0f3d3c9558d 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -118,7 +118,7 @@ struct objtool_file *objtool_open_read(const char *_obj= name) if (!file.elf) return NULL; =20 - if (backup && !objtool_create_backup(objname)) { + if (opts.backup && !objtool_create_backup(objname)) { WARN("can't create backup file"); return NULL; } @@ -129,7 +129,7 @@ struct objtool_file *objtool_open_read(const char *_obj= name) INIT_LIST_HEAD(&file.static_call_list); INIT_LIST_HEAD(&file.mcount_loc_list); INIT_LIST_HEAD(&file.endbr_list); - file.ignore_unreachables =3D no_unreachable; + file.ignore_unreachables =3D opts.no_unreachable; file.hints =3D false; =20 return &file; @@ -137,7 +137,7 @@ struct objtool_file *objtool_open_read(const char *_obj= name) =20 void objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func) { - if (!noinstr) + if (!opts.noinstr) return; =20 if (!f->pv_ops) { --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5AF3C433EF for ; Wed, 13 Apr 2022 23:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239214AbiDMXXG (ORCPT ); Wed, 13 Apr 2022 19:23:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239251AbiDMXWg (ORCPT ); Wed, 13 Apr 2022 19:22:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C46FF25C4C for ; Wed, 13 Apr 2022 16:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892011; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6PUsjixtT/2aqcPCo361GT/5WWbFX2OcpIYw6VwAndM=; b=jF6/E8suuNasnNOW14Dy0YOuDd6VJpGQAdW2Tb6ZsCxZMFUu2W8L5Irz1eerXa3VT4wBjN cOklBK+bjsLJxy6uVhc7FxaR0BgiK6koMFUWs5OP4+NEKo5fvPR5JQNaeSzJ1MV13o1jl8 BE2HqXBgV+EdAMhD6jxW0TjV6Nh6NeI= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-298--sKG9eGpNEKvOh_NcAcE7w-1; Wed, 13 Apr 2022 19:20:10 -0400 X-MC-Unique: -sKG9eGpNEKvOh_NcAcE7w-1 Received: by mail-qk1-f199.google.com with SMTP id bi19-20020a05620a319300b0069c16295aabso2178775qkb.1 for ; Wed, 13 Apr 2022 16:20:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6PUsjixtT/2aqcPCo361GT/5WWbFX2OcpIYw6VwAndM=; b=AzqWPvMiBlyni8pModGiVvrtLwOUJyee6nQkQteiN43sKrwvnEiPcLne6Llu8qTYa8 xTmPWAIXUzYxAPzkOfR8S0HRe2oAKoCuLbpyWk+XL67QAVhwohM9knRhHxQHB/VJVnVy 0gqr7GRdn/dngDyzVvdX85HBTSGFRCIPpQkaBkisAinCaK3c8d3ryp1u7K5afIq2nkDC psmysYC6B8djAGE9aBT8A2GnBdgkOgBQwtsfd2jcIM3NoGt14DZlU6B3SL3PTeJrp1zR x0gCk2b4oKcRs0Pmw1koNF93y1xwT7s46pqP3xa+n2n2n4ZiVhRiKLgyasGqRDBz/29n QlZA== X-Gm-Message-State: AOAM532lVgkRPAY/Wko8bnI2XJNasamHecKOrcRZcfuB3AcYFhWK4bRF 9jp8uTamX0/1RdfkOgpfiyiMSJIoh7wsLHbMtOn281wvJv7wUB2jm8RYTOdsqpSgoqouVMNfI7M EbFhE/+P/H8Z9TeZGHuodaAEi X-Received: by 2002:a0c:e388:0:b0:444:2d7e:d84c with SMTP id a8-20020a0ce388000000b004442d7ed84cmr984011qvl.9.1649892010239; Wed, 13 Apr 2022 16:20:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOEeyK7udZnwdb3G9wcJaYKFCSYcUQ34IUlFYzkLgpJi+fKX1uhDThPvvguZs/vlxPgYnReA== X-Received: by 2002:a0c:e388:0:b0:444:2d7e:d84c with SMTP id a8-20020a0ce388000000b004442d7ed84cmr983995qvl.9.1649892009911; Wed, 13 Apr 2022 16:20:09 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:09 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 08/18] objtool: Ditch subcommands Date: Wed, 13 Apr 2022 16:19:43 -0700 Message-Id: <9476ef23a62daa2caf99689c1f56e358f7f25f69.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Objtool has a fairly singular focus. It runs on object files and does validations and transformations which can be combined in various ways. The subcommand model has never been a good fit, making it awkward to combine and remove options. Remove the "check" and "orc" subcommands in favor of a more traditional cmdline option model. This makes it much more flexible to use, and easier to port individual features to other arches. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 13 ++-- tools/objtool/Build | 12 ++- tools/objtool/Makefile | 8 +- tools/objtool/builtin-check.c | 61 +++++++++++++--- tools/objtool/builtin-orc.c | 73 ------------------- tools/objtool/check.c | 8 ++ tools/objtool/include/objtool/builtin.h | 10 ++- tools/objtool/objtool.c | 97 +------------------------ tools/objtool/weak.c | 9 +-- 10 files changed, 82 insertions(+), 211 deletions(-) delete mode 100644 tools/objtool/builtin-orc.c diff --git a/scripts/Makefile.build b/scripts/Makefile.build index dd9d582808d6..116c7272b41c 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -227,9 +227,9 @@ ifdef CONFIG_STACK_VALIDATION objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ - $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ + $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index c6e9fef61b11..f6db79b11573 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -113,9 +113,6 @@ objtool_link() =20 # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. - if is_enabled CONFIG_UNWINDER_ORC; then - objtoolcmd=3D"orc generate" - fi =20 if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt=3D"${objtoolopt} --ibt" @@ -125,6 +122,10 @@ objtool_link() objtoolopt=3D"${objtoolopt} --mcount" fi =20 + if is_enabled CONFIG_UNWINDER_ORC; then + objtoolopt=3D"${objtoolopt} --orc" + fi + objtoolopt=3D"${objtoolopt} --lto" fi =20 @@ -134,10 +135,6 @@ objtool_link() =20 if [ -n "${objtoolopt}" ]; then =20 - if [ -z "${objtoolcmd}" ]; then - objtoolcmd=3D"check" - fi - if is_enabled CONFIG_RETPOLINE; then objtoolopt=3D"${objtoolopt} --retpoline" fi @@ -161,7 +158,7 @@ objtool_link() objtoolopt=3D"${objtoolopt} --vmlinux" =20 info OBJTOOL ${1} - tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} + tools/objtool/objtool ${objtoolopt} ${1} fi } =20 diff --git a/tools/objtool/Build b/tools/objtool/Build index b7222d5cc7bc..33f2ee5a46d3 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -2,17 +2,15 @@ objtool-y +=3D arch/$(SRCARCH)/ =20 objtool-y +=3D weak.o =20 -objtool-$(SUBCMD_CHECK) +=3D check.o -objtool-$(SUBCMD_CHECK) +=3D special.o -objtool-$(SUBCMD_ORC) +=3D check.o -objtool-$(SUBCMD_ORC) +=3D orc_gen.o -objtool-$(SUBCMD_ORC) +=3D orc_dump.o - +objtool-y +=3D check.o +objtool-y +=3D special.o objtool-y +=3D builtin-check.o -objtool-y +=3D builtin-orc.o objtool-y +=3D elf.o objtool-y +=3D objtool.o =20 +objtool-$(BUILD_ORC) +=3D orc_gen.o +objtool-$(BUILD_ORC) +=3D orc_dump.o + objtool-y +=3D libstring.o objtool-y +=3D libctype.o objtool-y +=3D str_error_r.o diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 0dbd397f319d..061cf1cd42c4 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -39,15 +39,13 @@ CFLAGS +=3D $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) =20 AWK =3D awk =20 -SUBCMD_CHECK :=3D n -SUBCMD_ORC :=3D n +BUILD_ORC :=3D n =20 ifeq ($(SRCARCH),x86) - SUBCMD_CHECK :=3D y - SUBCMD_ORC :=3D y + BUILD_ORC :=3D y endif =20 -export SUBCMD_CHECK SUBCMD_ORC +export BUILD_ORC export srctree OUTPUT CFLAGS SRCARCH AWK include $(srctree)/tools/build/Makefile.include =20 diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 4f4a087720b3..3df46e9b4b03 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -3,16 +3,6 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 -/* - * objtool check: - * - * This command analyzes every .o file and ensures the validity of its sta= ck - * trace metadata. It enforces a set of rules on asm code and C inline - * assembly code so that stack traces can be reliable. - * - * For more information, see tools/objtool/Documentation/stack-validation.= txt. - */ - #include #include #include @@ -22,7 +12,7 @@ struct opts opts; =20 static const char * const check_usage[] =3D { - "objtool check [] file.o", + "objtool [] file.o", NULL, }; =20 @@ -31,14 +21,31 @@ static const char * const env_usage[] =3D { NULL, }; =20 +static int parse_dumpstr(const struct option *opt, const char *str, int un= set) +{ + if (unset || !str) { + opts.dump =3D DUMP_NONE; + return 0; + } + + if (!strcmp(str, "orc")) { + opts.dump =3D DUMP_ORC; + return 0; + } + + return -1; +} + const struct option check_options[] =3D { OPT_GROUP("Actions:"), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), + OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"), OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('S', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), + OPT_CALLBACK(0, "dump", NULL, "orc", "dump object data", parse_dumpstr), =20 OPT_GROUP("Options:"), OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"), @@ -81,7 +88,31 @@ int cmd_parse_options(int argc, const char **argv, const= char * const usage[]) return argc; } =20 -int cmd_check(int argc, const char **argv) +static bool opts_valid(void) +{ + if (opts.ibt || + opts.mcount || + opts.noinstr || + opts.orc || + opts.retpoline || + opts.sls || + opts.uaccess) { + if (opts.dump) { + fprintf(stderr, "--dump can't be combined with other options\n"); + return false; + } + + return true; + } + + if (opts.dump) + return true; + + fprintf(stderr, "At least one command required\n"); + return false; +} + +int objtool_run(int argc, const char **argv) { const char *objname; struct objtool_file *file; @@ -90,6 +121,12 @@ int cmd_check(int argc, const char **argv) argc =3D cmd_parse_options(argc, argv, check_usage); objname =3D argv[0]; =20 + if (!opts_valid()) + return 1; + + if (opts.dump =3D=3D DUMP_ORC) + return orc_dump(objname); + file =3D objtool_open_read(objname); if (!file) return 1; diff --git a/tools/objtool/builtin-orc.c b/tools/objtool/builtin-orc.c deleted file mode 100644 index 17f8b9307738..000000000000 --- a/tools/objtool/builtin-orc.c +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2017 Josh Poimboeuf - */ - -/* - * objtool orc: - * - * This command analyzes a .o file and adds .orc_unwind and .orc_unwind_ip - * sections to it, which is used by the in-kernel ORC unwinder. - * - * This command is a superset of "objtool check". - */ - -#include -#include -#include - -static const char *orc_usage[] =3D { - "objtool orc generate [] file.o", - "objtool orc dump file.o", - NULL, -}; - -int cmd_orc(int argc, const char **argv) -{ - const char *objname; - - argc--; argv++; - if (argc <=3D 0) - usage_with_options(orc_usage, check_options); - - if (!strncmp(argv[0], "gen", 3)) { - struct objtool_file *file; - int ret; - - argc =3D cmd_parse_options(argc, argv, orc_usage); - objname =3D argv[0]; - - file =3D objtool_open_read(objname); - if (!file) - return 1; - - ret =3D check(file); - if (ret) - return ret; - - if (list_empty(&file->insn_list)) - return 0; - - ret =3D orc_create(file); - if (ret) - return ret; - - if (!file->elf->changed) - return 0; - - return elf_write(file->elf); - } - - if (!strcmp(argv[0], "dump")) { - if (argc !=3D 2) - usage_with_options(orc_usage, check_options); - - objname =3D argv[1]; - - return orc_dump(objname); - } - - usage_with_options(orc_usage, check_options); - - return 0; -} diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5059c097c563..490ed3560d99 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3950,6 +3950,14 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 + if (opts.orc && !list_empty(&file->insn_list)) { + ret =3D orc_create(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } + + if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); printf("nr_cfi: %ld\n", nr_cfi); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 87c1a7351e3c..0cac9bd6a97f 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -9,11 +9,18 @@ =20 extern const struct option check_options[]; =20 +enum dump { + DUMP_NONE, + DUMP_ORC, +}; + struct opts { /* actions: */ + enum dump dump; bool ibt; bool mcount; bool noinstr; + bool orc; bool retpoline; bool sls; bool uaccess; @@ -34,7 +41,6 @@ extern struct opts opts; =20 extern int cmd_parse_options(int argc, const char **argv, const char * con= st usage[]); =20 -extern int cmd_check(int argc, const char **argv); -extern int cmd_orc(int argc, const char **argv); +extern int objtool_run(int argc, const char **argv); =20 #endif /* _BUILTIN_H */ diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index a0f3d3c9558d..512669ce064c 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -3,16 +3,6 @@ * Copyright (C) 2015 Josh Poimboeuf */ =20 -/* - * objtool: - * - * The 'check' subcmd analyzes every .o file and ensures the validity of i= ts - * stack trace metadata. It enforces a set of rules on asm code and C inl= ine - * assembly code so that stack traces can be reliable. - * - * For more information, see tools/objtool/Documentation/stack-validation.= txt. - */ - #include #include #include @@ -26,20 +16,6 @@ #include #include =20 -struct cmd_struct { - const char *name; - int (*fn)(int, const char **); - const char *help; -}; - -static const char objtool_usage_string[] =3D - "objtool COMMAND [ARGS]"; - -static struct cmd_struct objtool_cmds[] =3D { - {"check", cmd_check, "Perform stack metadata validation on an object file= " }, - {"orc", cmd_orc, "Generate in-place ORC unwind tables for an object file= " }, -}; - bool help; =20 const char *objname; @@ -161,70 +137,6 @@ void objtool_pv_add(struct objtool_file *f, int idx, s= truct symbol *func) f->pv_ops[idx].clean =3D false; } =20 -static void cmd_usage(void) -{ - unsigned int i, longest =3D 0; - - printf("\n usage: %s\n\n", objtool_usage_string); - - for (i =3D 0; i < ARRAY_SIZE(objtool_cmds); i++) { - if (longest < strlen(objtool_cmds[i].name)) - longest =3D strlen(objtool_cmds[i].name); - } - - puts(" Commands:"); - for (i =3D 0; i < ARRAY_SIZE(objtool_cmds); i++) { - printf(" %-*s ", longest, objtool_cmds[i].name); - puts(objtool_cmds[i].help); - } - - printf("\n"); - - if (!help) - exit(129); - exit(0); -} - -static void handle_options(int *argc, const char ***argv) -{ - while (*argc > 0) { - const char *cmd =3D (*argv)[0]; - - if (cmd[0] !=3D '-') - break; - - if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h")) { - help =3D true; - break; - } else { - fprintf(stderr, "Unknown option: %s\n", cmd); - cmd_usage(); - } - - (*argv)++; - (*argc)--; - } -} - -static void handle_internal_command(int argc, const char **argv) -{ - const char *cmd =3D argv[0]; - unsigned int i, ret; - - for (i =3D 0; i < ARRAY_SIZE(objtool_cmds); i++) { - struct cmd_struct *p =3D objtool_cmds+i; - - if (strcmp(p->name, cmd)) - continue; - - ret =3D p->fn(argc, argv); - - exit(ret); - } - - cmd_usage(); -} - int main(int argc, const char **argv) { static const char *UNUSED =3D "OBJTOOL_NOT_IMPLEMENTED"; @@ -233,14 +145,7 @@ int main(int argc, const char **argv) exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED); pager_init(UNUSED); =20 - argv++; - argc--; - handle_options(&argc, &argv); - - if (!argc || help) - cmd_usage(); - - handle_internal_command(argc, argv); + objtool_run(argc, argv); =20 return 0; } diff --git a/tools/objtool/weak.c b/tools/objtool/weak.c index 8314e824db4a..d83f607733b0 100644 --- a/tools/objtool/weak.c +++ b/tools/objtool/weak.c @@ -15,17 +15,12 @@ return ENOSYS; \ }) =20 -int __weak check(struct objtool_file *file) -{ - UNSUPPORTED("check subcommand"); -} - int __weak orc_dump(const char *_objname) { - UNSUPPORTED("orc"); + UNSUPPORTED("ORC"); } =20 int __weak orc_create(struct objtool_file *file) { - UNSUPPORTED("orc"); + UNSUPPORTED("ORC"); } --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FD95C433EF for ; Wed, 13 Apr 2022 23:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233196AbiDMXXK (ORCPT ); Wed, 13 Apr 2022 19:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239252AbiDMXWg (ORCPT ); Wed, 13 Apr 2022 19:22:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 328D123BF4 for ; Wed, 13 Apr 2022 16:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892013; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BgoysvRYI7jiT6YTcwzlIA96pkBT7Y5XEienP3vKiOM=; b=J5Th5tgrEEyIhguyNWqcMz89AHT9Ob14f28OODBrV328I176NVtVpzEihPDgXH6bLjMEZ4 HO86cHh02pqY/Yc2n8BIVK/IESe1XOMlcybfje4g6CD7++gSle9y3iG4ZMg3PajUWtYhrI ELY2IG28fGq4NPaxjKuJewIQtZ/tF/Y= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-4T5RH9FANm-CK4Hu7lSdrQ-1; Wed, 13 Apr 2022 19:20:12 -0400 X-MC-Unique: 4T5RH9FANm-CK4Hu7lSdrQ-1 Received: by mail-qk1-f197.google.com with SMTP id ay14-20020a05620a178e00b0069a9c319c64so2174930qkb.3 for ; Wed, 13 Apr 2022 16:20:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BgoysvRYI7jiT6YTcwzlIA96pkBT7Y5XEienP3vKiOM=; b=LPBXN0LdHs4RXTgtKbMgehiq/SAs299yLWBE7aiUL6q3jCxu8CPpETGSQvgbuY1gYh Qoy4JU4TPAAXtjfgs/XgrhuSH5uSY17dhtlc2wRSY+QDkgNGT/D611eRR08UzV4n0V0p 3F5EVWZtdXSCaIc7WKuT6w7sircvHuZmxIUvnUZEPUaE7SYx3YGmv4yoY8kPmNypXMFz pwLUbv6JYzlsRDAJ/B5CFqo9U9csVGF9zeO4vZWONBtnht5KUVYddWYr4aa3H6kifkVi /MbvRRg67jePWeNhukIJwMR8sDL4kse9UimVuFEJ6Y8ks52mn+PyYa/2poGlNy5qZI+h 0Dbg== X-Gm-Message-State: AOAM5305QFVAQgJDuVuQseE/cZAfq5JYROlTjAjM6Z3nb1a+owZ2CzYc hMcZHvHbyPbSQxT9aPGoM0XC/uQaQ1Pj7Aen4Tgqji+JcKkGs4PF9fW9owHJ5NyDjv+4L+L77a4 w/N6mDbVQFV6BVp+jmud95cTq X-Received: by 2002:a05:6214:d87:b0:443:6f15:fe33 with SMTP id e7-20020a0562140d8700b004436f15fe33mr10692040qve.50.1649892011629; Wed, 13 Apr 2022 16:20:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/pZEa9SgFWf0W/cHE7busWtIbByRWu+vm20SnbmxjMNMYejlz00594UibKGPkjnMR/mH25Q== X-Received: by 2002:a05:6214:d87:b0:443:6f15:fe33 with SMTP id e7-20020a0562140d8700b004436f15fe33mr10692028qve.50.1649892011419; Wed, 13 Apr 2022 16:20:11 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:10 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 09/18] objtool: Add stack validation cmdline option Date: Wed, 13 Apr 2022 16:19:44 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make stack validation an explicit cmdline option so that individual objtool features can be enabled individually by other arches. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 ++++ tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 28 +++++++++++++------------ tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 116c7272b41c..d5e15ae29156 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -232,6 +232,7 @@ objtool_args =3D \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ + $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index f6db79b11573..0140bfa32c0c 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -126,6 +126,10 @@ objtool_link() objtoolopt=3D"${objtoolopt} --orc" fi =20 + if is_enabled CONFIG_STACK_VALIDATION; then + objtoolopt=3D"${objtoolopt} --stackval" + fi + objtoolopt=3D"${objtoolopt} --lto" fi =20 diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 3df46e9b4b03..a6a86e2d0598 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -44,6 +44,7 @@ const struct option check_options[] =3D { OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"), OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('S', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), + OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate stack unwinding ru= les"), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), OPT_CALLBACK(0, "dump", NULL, "orc", "dump object data", parse_dumpstr), =20 @@ -96,6 +97,7 @@ static bool opts_valid(void) opts.orc || opts.retpoline || opts.sls || + opts.stackval || opts.uaccess) { if (opts.dump) { fprintf(stderr, "--dump can't be combined with other options\n"); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 490ed3560d99..bb25937b2d1c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3900,25 +3900,27 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 - ret =3D validate_functions(file); - if (ret < 0) - goto out; - warnings +=3D ret; - - ret =3D validate_unwind_hints(file, NULL); - if (ret < 0) - goto out; - warnings +=3D ret; + if (opts.stackval || opts.orc || opts.uaccess) { + ret =3D validate_functions(file); + if (ret < 0) + goto out; + warnings +=3D ret; =20 - if (opts.ibt) { - ret =3D validate_ibt(file); + ret =3D validate_unwind_hints(file, NULL); if (ret < 0) goto out; warnings +=3D ret; + + if (!warnings) { + ret =3D validate_reachable_instructions(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } } =20 - if (!warnings) { - ret =3D validate_reachable_instructions(file); + if (opts.ibt) { + ret =3D validate_ibt(file); if (ret < 0) goto out; warnings +=3D ret; diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 0cac9bd6a97f..edb0f550727b 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -23,6 +23,7 @@ struct opts { bool orc; bool retpoline; bool sls; + bool stackval; bool uaccess; =20 /* options: */ --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEBF5C433EF for ; Wed, 13 Apr 2022 23:20:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239290AbiDMXXU (ORCPT ); Wed, 13 Apr 2022 19:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239263AbiDMXWi (ORCPT ); Wed, 13 Apr 2022 19:22:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 16D4323BF4 for ; Wed, 13 Apr 2022 16:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892015; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1498SmuR6dXVDwcCXccoABHA14ZfP4NbQRKlblxZUE8=; b=NWIlRqslFoSjQkWeQLQqoPdUEzYWhhL0bhRMOPQlNe+k4tvXWOSgEzB1FhA45oQYfm4bZo xT6jXMTMjghksGbSQCC9acHndXW81k8BUO2HSybBPJ03TFhypQ5uPesQG4aUNjKZPmRX3D jF+xoE3uIsvTYhf9o/Qz27VNkPwzjP4= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-eMtUgswPNB2D_v3ikpw_OQ-1; Wed, 13 Apr 2022 19:20:14 -0400 X-MC-Unique: eMtUgswPNB2D_v3ikpw_OQ-1 Received: by mail-qk1-f199.google.com with SMTP id l68-20020a378947000000b0067df0c430d8so2155275qkd.13 for ; Wed, 13 Apr 2022 16:20:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1498SmuR6dXVDwcCXccoABHA14ZfP4NbQRKlblxZUE8=; b=FYWH3IBSlhl8t10d7Cn7phHCLdOM55bC0JMCeTKtenbAJxi/cWFSbjW/edQROTF0TX Oglp7lmxvD1EWgckZk1sXxEKSMOsPSs+sg1zWGb/0V+vjK2hFBEur/+iJdCot9K6f+RP xahN4CUhXJQF+p2UgpMbr6a5NmRIsgiV6njv8hgYuHGyl5bR6NFI6gftW1SFF1kCj0I9 eYY/clFM/wazVACIdjfjc4CQhTXBGLmUXLmJbqvL03pkq35SE0IYTRigdAlWi+vgrtCF IzBxCgPyM73vnAyOTD+qzu4yA/1Nglz5xDtKNdqZe2Fn8aqgBoNCMShSQDkGUl/pjCzQ CmSg== X-Gm-Message-State: AOAM532bFC5AGD9ni6AZWs1ybCxH7Ju2zhVlrw5SALSg85DFmAYXYyrm X603S+eJHPhq/7G+eCID6MY6R4P2BrcIYgzlhJDIRPhrPfJ66EKxrq+ED3xp4SWCMPdkQK7hvY0 hIfi+u1k6JNiRellWyF7dfqwj X-Received: by 2002:a05:622a:1f0c:b0:2ed:1211:364 with SMTP id ca12-20020a05622a1f0c00b002ed12110364mr8963158qtb.390.1649892013294; Wed, 13 Apr 2022 16:20:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHHULL64mNi2ZC2/GeA9LWKnn81plj+ysbuIU1b3kMkC+vGB7l+2HTZxadeCnUO9GKcyV/3w== X-Received: by 2002:a05:622a:1f0c:b0:2ed:1211:364 with SMTP id ca12-20020a05622a1f0c00b002ed12110364mr8963145qtb.390.1649892012967; Wed, 13 Apr 2022 16:20:12 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:12 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 10/18] objtool: Extricate ibt from stack validation Date: Wed, 13 Apr 2022 16:19:45 -0700 Message-Id: <44a73f724b51c4a994edc43536b7a7ee5e972b40.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extricate ibt from validate_branch() in preparation for making stack validation optional. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 253 ++++++++++++++++++++---------------------- 1 file changed, 120 insertions(+), 133 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bb25937b2d1c..1b1e7a4ae18b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3183,114 +3183,6 @@ static struct instruction *next_insn_to_validate(st= ruct objtool_file *file, return next_insn_same_sec(file, insn); } =20 -static struct instruction * -validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc) -{ - struct instruction *dest; - struct section *sec; - unsigned long off; - - sec =3D reloc->sym->sec; - off =3D reloc->sym->offset; - - if ((reloc->sec->base->sh.sh_flags & SHF_EXECINSTR) && - (reloc->type =3D=3D R_X86_64_PC32 || reloc->type =3D=3D R_X86_64_PLT3= 2)) - off +=3D arch_dest_reloc_offset(reloc->addend); - else - off +=3D reloc->addend; - - dest =3D find_insn(file, sec, off); - if (!dest) - return NULL; - - if (dest->type =3D=3D INSN_ENDBR) { - if (!list_empty(&dest->call_node)) - list_del_init(&dest->call_node); - - return NULL; - } - - if (reloc->sym->static_call_tramp) - return NULL; - - return dest; -} - -static void warn_noendbr(const char *msg, struct section *sec, unsigned lo= ng offset, - struct instruction *dest) -{ - WARN_FUNC("%srelocation to !ENDBR: %s", sec, offset, msg, - offstr(dest->sec, dest->offset, false)); -} - -static void validate_ibt_dest(struct objtool_file *file, struct instructio= n *insn, - struct instruction *dest) -{ - if (dest->func && dest->func =3D=3D insn->func) { - /* - * Anything from->to self is either _THIS_IP_ or IRET-to-self. - * - * There is no sane way to annotate _THIS_IP_ since the compiler treats = the - * relocation as a constant and is happy to fold in offsets, skewing any - * annotation we do, leading to vast amounts of false-positives. - * - * There's also compiler generated _THIS_IP_ through KCOV and - * such which we have no hope of annotating. - * - * As such, blanket accept self-references without issue. - */ - return; - } - - if (dest->noendbr) - return; - - warn_noendbr("", insn->sec, insn->offset, dest); -} - -static void validate_ibt_insn(struct objtool_file *file, struct instructio= n *insn) -{ - struct instruction *dest; - struct reloc *reloc; - - switch (insn->type) { - case INSN_CALL: - case INSN_CALL_DYNAMIC: - case INSN_JUMP_CONDITIONAL: - case INSN_JUMP_UNCONDITIONAL: - case INSN_JUMP_DYNAMIC: - case INSN_JUMP_DYNAMIC_CONDITIONAL: - case INSN_RETURN: - /* - * We're looking for code references setting up indirect code - * flow. As such, ignore direct code flow and the actual - * dynamic branches. - */ - return; - - case INSN_NOP: - /* - * handle_group_alt() will create INSN_NOP instruction that - * don't belong to any section, ignore all NOP since they won't - * carry a (useful) relocation anyway. - */ - return; - - default: - break; - } - - for (reloc =3D insn_reloc(file, insn); - reloc; - reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, - reloc->offset + 1, - (insn->offset + insn->len) - (reloc->offset + 1))) { - dest =3D validate_ibt_reloc(file, reloc); - if (dest) - validate_ibt_dest(file, insn, dest); - } -} - /* * Follow the branch starting at the given instruction, and recursively fo= llow * any other branches (jumps). Meanwhile, track the frame pointer state at @@ -3500,9 +3392,6 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, break; } =20 - if (opts.ibt) - validate_ibt_insn(file, insn); - if (insn->dead_end) return 0; =20 @@ -3788,48 +3677,146 @@ static int validate_functions(struct objtool_file = *file) return warnings; } =20 -static int validate_ibt(struct objtool_file *file) +static void mark_endbr_used(struct instruction *insn) { - struct section *sec; + if (!list_empty(&insn->call_node)) + list_del_init(&insn->call_node); +} + +static int validate_ibt_insn(struct objtool_file *file, struct instruction= *insn) +{ + struct instruction *dest; struct reloc *reloc; + unsigned long off; + int warnings =3D 0; =20 - for_each_sec(file, sec) { - bool is_data; + /* + * Looking for function pointer load relocations. Ignore + * direct/indirect branches: + */ + switch (insn->type) { + case INSN_CALL: + case INSN_CALL_DYNAMIC: + case INSN_JUMP_CONDITIONAL: + case INSN_JUMP_UNCONDITIONAL: + case INSN_JUMP_DYNAMIC: + case INSN_JUMP_DYNAMIC_CONDITIONAL: + case INSN_RETURN: + case INSN_NOP: + return 0; + default: + break; + } =20 - /* already done in validate_branch() */ - if (sec->sh.sh_flags & SHF_EXECINSTR) - continue; + for (reloc =3D insn_reloc(file, insn); + reloc; + reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, + reloc->offset + 1, + (insn->offset + insn->len) - (reloc->offset + 1))) { =20 - if (!sec->reloc) + /* + * static_call_update() references the trampoline, which + * doesn't have (or need) ENDBR. Skip warning in that case. + */ + if (reloc->sym->static_call_tramp) continue; =20 - if (!strncmp(sec->name, ".orc", 4)) - continue; + off =3D reloc->sym->offset; + if (reloc->type =3D=3D R_X86_64_PC32 || reloc->type =3D=3D R_X86_64_PLT3= 2) + off +=3D arch_dest_reloc_offset(reloc->addend); + else + off +=3D reloc->addend; =20 - if (!strncmp(sec->name, ".discard", 8)) + dest =3D find_insn(file, reloc->sym->sec, off); + if (!dest) continue; =20 - if (!strncmp(sec->name, ".debug", 6)) + if (dest->type =3D=3D INSN_ENDBR) { + mark_endbr_used(dest); continue; + } =20 - if (!strcmp(sec->name, "_error_injection_whitelist")) + if (dest->func && dest->func =3D=3D insn->func) { + /* + * Anything from->to self is either _THIS_IP_ or + * IRET-to-self. + * + * There is no sane way to annotate _THIS_IP_ since the + * compiler treats the relocation as a constant and is + * happy to fold in offsets, skewing any annotation we + * do, leading to vast amounts of false-positives. + * + * There's also compiler generated _THIS_IP_ through + * KCOV and such which we have no hope of annotating. + * + * As such, blanket accept self-references without + * issue. + */ continue; + } =20 - if (!strcmp(sec->name, "_kprobe_blacklist")) + if (dest->noendbr) continue; =20 - is_data =3D strstr(sec->name, ".data") || strstr(sec->name, ".rodata"); + WARN_FUNC("relocation to !ENDBR: %s", + insn->sec, insn->offset, + offstr(dest->sec, dest->offset, false)); =20 - list_for_each_entry(reloc, &sec->reloc->reloc_list, list) { - struct instruction *dest; + warnings++; + } =20 - dest =3D validate_ibt_reloc(file, reloc); - if (is_data && dest && !dest->noendbr) - warn_noendbr("data ", sec, reloc->offset, dest); - } + return warnings; +} + +static int validate_ibt_data_reloc(struct objtool_file *file, + struct reloc *reloc) +{ + struct instruction *dest; + + dest =3D find_insn(file, reloc->sym->sec, + reloc->sym->offset + reloc->addend); + if (!dest) + return 0; + + if (dest->type =3D=3D INSN_ENDBR) { + mark_endbr_used(dest); + return 0; } =20 - return 0; + if (dest->noendbr) + return 0; + + WARN_FUNC("data relocation to !ENDBR: %s", + reloc->sec->base, reloc->offset, + offstr(dest->sec, dest->offset, false)); + + return 1; +} + + +static int validate_ibt(struct objtool_file *file) +{ + struct section *sec; + struct reloc *reloc; + struct instruction *insn; + int warnings =3D 0; + + for_each_insn(file, insn) + warnings +=3D validate_ibt_insn(file, insn); + + for_each_sec(file, sec) { + + if (!strstr(sec->name, ".data") && !strstr(sec->name, ".rodata")) + continue; + + if (!sec->reloc) + continue; + + list_for_each_entry(reloc, &sec->reloc->reloc_list, list) + warnings +=3D validate_ibt_data_reloc(file, reloc); + } + + return warnings; } =20 static int validate_reachable_instructions(struct objtool_file *file) --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 011D0C433EF for ; Wed, 13 Apr 2022 23:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239262AbiDMXXZ (ORCPT ); Wed, 13 Apr 2022 19:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239273AbiDMXWl (ORCPT ); Wed, 13 Apr 2022 19:22:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E37D223BC5 for ; Wed, 13 Apr 2022 16:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892017; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VyhT3BT6VMq8FLjVnc4agqzIjqfTJuNBZf7A2XDS6Y8=; b=SkAnicZEAS5Inizp8oNRB4jwssEi5nNr3vDIYk6kUwjDNP0NWsSm8olE/BD2BKQ7kQeXC3 a+QNQuwQANs9SayPHYYAYTEe4YhaaiScA7gKHqj0PVWrbpjz6Z/AV2eCgKLEBEOue6NUjR qfztpgQigT+oszFI3UgPLzZeUQtejnw= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-318-2GdzvJNdN-emmUpxWzTOqQ-1; Wed, 13 Apr 2022 19:20:15 -0400 X-MC-Unique: 2GdzvJNdN-emmUpxWzTOqQ-1 Received: by mail-qv1-f71.google.com with SMTP id e10-20020a0562140d8a00b00443c3595342so3020722qve.8 for ; Wed, 13 Apr 2022 16:20:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VyhT3BT6VMq8FLjVnc4agqzIjqfTJuNBZf7A2XDS6Y8=; b=NlMbdwRGnS2eQlGNszWGlFEopSSifG864mC1286KcMHGwCnV/WME+8lu0xGXt/0GEv OvES0UuSdzynnfL/7I6jQCCIzzYk3by4m1HP5o/V03uDlyCMgCfqL+lIxi6xC4cfWm/0 nZrA8B8zNiMXu+mFzwqiyfvnmblyDjG3Q3IgOnFjLpLDBYnFlBO0Q3vX5D9gUzBnHhzB bkyVVvSKLEICvyvd/XEqpuGsCm3lok3VzfLWABp9hkaym+uim5RtRhyo+gq10nBHrBu8 gdGMgnuBCWZ00kxcFv9BywjlSTLGz9RPV1HJv5BI1e5AxZDUpbspQJ/Pr8UUOlqSwADI laXQ== X-Gm-Message-State: AOAM532TcY7lhn6PDcfFS0i9+ZLETRzezckAPtwxR2QqYcBEADZ7EYhM LtusU6KrNQfJGFuvwc8+dTiWAJDqOE2wJgxUAAcwHi31gdsq+fUyzN/S5m0Q6UdkcUY7KjNhxyW Uc/qsn3ZXsMOw6VY/PER1MoGA X-Received: by 2002:a05:620a:240a:b0:67d:5514:eec6 with SMTP id d10-20020a05620a240a00b0067d5514eec6mr8946803qkn.324.1649892014785; Wed, 13 Apr 2022 16:20:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsyfIsiyYhynsP25nm4RZis/Bd5omY01WxTq/3W4Am3hSVOdpZmoENvxFod6ATbpAoD5n68Q== X-Received: by 2002:a05:620a:240a:b0:67d:5514:eec6 with SMTP id d10-20020a05620a240a00b0067d5514eec6mr8946789qkn.324.1649892014436; Wed, 13 Apr 2022 16:20:14 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:13 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 11/18] objtool: Add CONFIG_OBJTOOL Date: Wed, 13 Apr 2022 16:19:46 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that stack validation is an optional feature of objtool, add CONFIG_OBJTOOL and replace most usages of CONFIG_STACK_VALIDATION with it. CONFIG_STACK_VALIDATION can now be considered to be frame-pointer specific. CONFIG_UNWINDER_ORC is already inherently valid for live patching, so no need to "validate" it. Signed-off-by: Josh Poimboeuf --- Makefile | 2 +- arch/Kconfig | 8 ++++++-- arch/x86/Kconfig | 18 ++++++++++------- arch/x86/Kconfig.debug | 2 +- arch/x86/include/asm/jump_label.h | 6 +++--- arch/x86/kernel/alternative.c | 6 +++--- include/linux/compiler.h | 6 +++--- include/linux/instrumentation.h | 6 +++--- include/linux/objtool.h | 6 +++--- kernel/trace/Kconfig | 1 + lib/Kconfig.debug | 20 ++++++++++--------- lib/Kconfig.kcsan | 3 ++- lib/Kconfig.ubsan | 2 +- scripts/Makefile.build | 4 ++-- scripts/link-vmlinux.sh | 32 +++++++++++++++++-------------- scripts/package/builddeb | 2 +- tools/include/linux/objtool.h | 6 +++--- 17 files changed, 73 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index 29e273d3f8cc..707dfbf643a2 100644 --- a/Makefile +++ b/Makefile @@ -1302,7 +1302,7 @@ install: sub_make_done :=3D # ------------------------------------------------------------------------= --- # Tools =20 -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL prepare: tools/objtool endif =20 diff --git a/arch/Kconfig b/arch/Kconfig index 29b0167c088b..04cdef16db24 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1028,11 +1028,14 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT depends on MMU select ARCH_HAS_ELF_RANDOMIZE =20 +config HAVE_OBJTOOL + bool + config HAVE_STACK_VALIDATION bool help - Architecture supports the 'objtool check' host tool command, which - performs compile-time stack metadata validation. + Architecture supports objtool compile-time frame pointer rule + validation. =20 config HAVE_RELIABLE_STACKTRACE bool @@ -1302,6 +1305,7 @@ config HAVE_STATIC_CALL config HAVE_STATIC_CALL_INLINE bool depends on HAVE_STATIC_CALL + select OBJTOOL =20 config HAVE_PREEMPT_DYNAMIC bool diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index b0142e01002e..bce0c23f3550 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -188,7 +188,7 @@ config X86 select HAVE_CONTEXT_TRACKING if X86_64 select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING select HAVE_C_RECORDMCOUNT - select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION + select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL select HAVE_BUILDTIME_MCOUNT_SORT select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS @@ -231,6 +231,7 @@ config X86 select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_NMI + select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS @@ -239,17 +240,17 @@ config X86 select HAVE_PCI select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT + select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API - select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || = UNWINDER_ORC) && STACK_VALIDATION + select HAVE_RELIABLE_STACKTRACE if UNWINDER_ORC || STACK_VALIDATION select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_SETUP_PER_CPU_AREA select HAVE_SOFTIRQ_ON_OWN_STACK select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR - select HAVE_STACK_VALIDATION if X86_64 + select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STATIC_CALL - select HAVE_STATIC_CALL_INLINE if HAVE_STACK_VALIDATION + select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL select HAVE_PREEMPT_DYNAMIC_CALL select HAVE_RSEQ select HAVE_SYSCALL_TRACEPOINTS @@ -268,7 +269,6 @@ config X86 select RTC_MC146818_LIB select SPARSE_IRQ select SRCU - select STACK_VALIDATION if HAVE_STACK_VALIDATION && (HAVE_STATIC_CALL_I= NLINE || RETPOLINE) select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT @@ -459,6 +459,7 @@ config GOLDFISH =20 config RETPOLINE bool "Avoid speculative indirect branches in kernel" + select OBJTOOL if HAVE_OBJTOOL default y help Compile kernel with the retpoline compiler options to guard against @@ -472,6 +473,7 @@ config CC_HAS_SLS config SLS bool "Mitigate Straight-Line-Speculation" depends on CC_HAS_SLS && X86_64 + select OBJTOOL if HAVE_OBJTOOL default n help Compile the kernel with straight-line-speculation options to guard @@ -1819,6 +1821,7 @@ config ARCH_RANDOM config X86_SMAP def_bool y prompt "Supervisor Mode Access Prevention" if EXPERT + select OBJTOOL if HAVE_OBJTOOL help Supervisor Mode Access Prevention (SMAP) is a security feature in newer Intel processors. There is a small @@ -1855,9 +1858,10 @@ config CC_HAS_IBT config X86_KERNEL_IBT prompt "Indirect Branch Tracking" bool - depends on X86_64 && CC_HAS_IBT && STACK_VALIDATION + depends on X86_64 && CC_HAS_IBT && HAVE_OBJTOOL # https://github.com/llvm/llvm-project/commit/9d7001eba9c4cb311e03cd8cdc2= 31f9e579f2d0f depends on !LD_IS_LLD || LLD_VERSION >=3D 140000 + select OBJTOOL help Build the kernel with support for Indirect Branch Tracking, a hardware support course-grain forward-edge Control Flow Integrity diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index d3a6f74a94bd..d872a7522e55 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug @@ -237,7 +237,7 @@ choice config UNWINDER_ORC bool "ORC unwinder" depends on X86_64 - select STACK_VALIDATION + select OBJTOOL help This option enables the ORC (Oops Rewind Capability) unwinder for unwinding kernel stack traces. It uses a custom data format which is diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_= label.h index 0449b125d27f..3ce0e67c579c 100644 --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -20,7 +20,7 @@ _ASM_PTR "%c0 + %c1 - .\n\t" \ ".popsection \n\t" =20 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL =20 static __always_inline bool arch_static_branch(struct static_key *key, boo= l branch) { @@ -34,7 +34,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key *key, bool bran return true; } =20 -#else +#else /* !CONFIG_OBJTOOL */ =20 static __always_inline bool arch_static_branch(struct static_key * const k= ey, const bool branch) { @@ -48,7 +48,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key * const key, co return true; } =20 -#endif /* STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ =20 static __always_inline bool arch_static_branch_jump(struct static_key * co= nst key, const bool branch) { diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d374cb3cf024..3c66073e7645 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -338,7 +338,7 @@ void __init_or_module noinline apply_alternatives(struc= t alt_instr *start, } } =20 -#if defined(CONFIG_RETPOLINE) && defined(CONFIG_STACK_VALIDATION) +#if defined(CONFIG_RETPOLINE) && defined(CONFIG_OBJTOOL) =20 /* * CALL/JMP *%\reg @@ -507,11 +507,11 @@ void __init_or_module noinline apply_retpolines(s32 *= start, s32 *end) } } =20 -#else /* !RETPOLINES || !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_RETPOLINE || !CONFIG_OBJTOOL */ =20 void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) { } =20 -#endif /* CONFIG_RETPOLINE && CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_RETPOLINE && CONFIG_OBJTOOL */ =20 #ifdef CONFIG_X86_KERNEL_IBT =20 diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 219aa5ddbc73..01ce94b58b42 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -109,7 +109,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f,= int val, #endif =20 /* Unreachable code */ -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL /* * These macros help objtool understand GCC code flow for unreachable code. * The __COUNTER__ based labels are a hack to make each instance of the ma= cros @@ -128,10 +128,10 @@ void ftrace_likely_update(struct ftrace_likely_data *= f, int val, /* Annotate a C jump table to allow objtool to follow the code flow */ #define __annotate_jump_table __section(".rodata..c_jump_table") =20 -#else +#else /* !CONFIG_OBJTOOL */ #define annotate_unreachable() #define __annotate_jump_table -#endif +#endif /* CONFIG_OBJTOOL */ =20 #ifndef unreachable # define unreachable() do { \ diff --git a/include/linux/instrumentation.h b/include/linux/instrumentatio= n.h index 24359b4a9605..9111a3704072 100644 --- a/include/linux/instrumentation.h +++ b/include/linux/instrumentation.h @@ -2,7 +2,7 @@ #ifndef __LINUX_INSTRUMENTATION_H #define __LINUX_INSTRUMENTATION_H =20 -#if defined(CONFIG_DEBUG_ENTRY) && defined(CONFIG_STACK_VALIDATION) +#ifdef CONFIG_VMLINUX_VALIDATION =20 #include =20 @@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ }) #define instrumentation_end() __instrumentation_end(__COUNTER__) -#else +#else /* !CONFIG_VMLINUX_VALIDATION */ # define instrumentation_begin() do { } while(0) # define instrumentation_end() do { } while(0) -#endif +#endif /* CONFIG_VMLINUX_VALIDATION */ =20 #endif /* __LINUX_INSTRUMENTATION_H */ diff --git a/include/linux/objtool.h b/include/linux/objtool.h index 586d35720f13..977d90ba642d 100644 --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -38,7 +38,7 @@ struct unwind_hint { #define UNWIND_HINT_TYPE_REGS_PARTIAL 2 #define UNWIND_HINT_TYPE_FUNC 3 =20 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL =20 #ifndef __ASSEMBLY__ =20 @@ -157,7 +157,7 @@ struct unwind_hint { =20 #endif /* __ASSEMBLY__ */ =20 -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ =20 #ifndef __ASSEMBLY__ =20 @@ -179,6 +179,6 @@ struct unwind_hint { .endm #endif =20 -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ =20 #endif /* _LINUX_OBJTOOL_H */ diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 2c43e327a619..2956bc277150 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -728,6 +728,7 @@ config FTRACE_MCOUNT_USE_OBJTOOL depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY depends on !FTRACE_MCOUNT_USE_CC depends on FTRACE_MCOUNT_RECORD + select OBJTOOL =20 config FTRACE_MCOUNT_USE_RECORDMCOUNT def_bool y diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 075cd25363ac..c0e4e47f3ce3 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -485,24 +485,25 @@ config FRAME_POINTER larger and slower, but it gives very useful debugging information in case of kernel bugs. (precise oopses/stacktraces/warnings) =20 +config OBJTOOL + bool + config STACK_VALIDATION bool "Compile-time stack metadata validation" - depends on HAVE_STACK_VALIDATION + depends on HAVE_STACK_VALIDATION && UNWINDER_FRAME_POINTER + select OBJTOOL default n help - Add compile-time checks to validate stack metadata, including frame - pointers (if CONFIG_FRAME_POINTER is enabled). This helps ensure - that runtime stack traces are more reliable. - - This is also a prerequisite for generation of ORC unwind data, which - is needed for CONFIG_UNWINDER_ORC. + Validate frame pointer rules at compile-time. This helps ensure that + runtime stack traces are more reliable. =20 For more information, see tools/objtool/Documentation/stack-validation.txt. =20 config VMLINUX_VALIDATION bool - depends on STACK_VALIDATION && DEBUG_ENTRY + depends on HAVE_OBJTOOL && DEBUG_ENTRY + select OBJTOOL default y =20 config VMLINUX_MAP @@ -2035,10 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || STACK_VALIDATION || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ GCC_VERSION >=3D 120000 || CLANG_VERSION >=3D 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC + select OBJTOOL if HAVE_OBJTOOL help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing). diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan index de022445fbba..901c3b509aca 100644 --- a/lib/Kconfig.kcsan +++ b/lib/Kconfig.kcsan @@ -187,7 +187,8 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on STACK_VALIDATION || CC_IS_GCC || CLANG_VERSION >=3D 140000 + depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >=3D 140000 + select OBJTOOL if HAVE_OBJTOOL help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers. diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan index f3c57ed51838..c4fe15d38b60 100644 --- a/lib/Kconfig.ubsan +++ b/lib/Kconfig.ubsan @@ -94,7 +94,7 @@ config UBSAN_UNREACHABLE bool "Perform checking for unreachable code" # objtool already handles unreachable checking and gets angry about # seeing UBSan instrumentation located in unreachable places. - depends on !STACK_VALIDATION + depends on !(OBJTOOL && (STACK_VALIDATION || UNWINDER_ORC || X86_SMAP)) depends on $(cc-option,-fsanitize=3Dunreachable) help This option enables -fsanitize=3Dunreachable which checks for control diff --git a/scripts/Makefile.build b/scripts/Makefile.build index d5e15ae29156..0f73e02b7cf1 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -222,7 +222,7 @@ cmd_record_mcount =3D $(if $(findstring $(strip $(CC_FL= AGS_FTRACE)),$(_c_flags)), $(sub_cmd_record_mcount)) endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT =20 -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL =20 objtool :=3D $(objtree)/tools/objtool/objtool =20 @@ -241,7 +241,7 @@ objtool_args =3D \ cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep =3D $(if $(objtool-enabled), { echo ; echo '$@: $$(wild= card $(objtool))' ; } >> $(dot-target).cmd) =20 -endif # CONFIG_STACK_VALIDATION +endif # CONFIG_OBJTOOL =20 ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) =20 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 0140bfa32c0c..5101a7fbfaaf 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -108,8 +108,11 @@ objtool_link() local objtoolcmd; local objtoolopt; =20 - if is_enabled CONFIG_STACK_VALIDATION && \ - ( is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT ); t= hen + if ! is_enabled CONFIG_OBJTOOL; then + return; + fi + + if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then =20 # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. @@ -126,10 +129,23 @@ objtool_link() objtoolopt=3D"${objtoolopt} --orc" fi =20 + if is_enabled CONFIG_RETPOLINE; then + objtoolopt=3D"${objtoolopt} --retpoline" + fi + + if is_enabled CONFIG_SLS; then + objtoolopt=3D"${objtoolopt} --sls" + fi + if is_enabled CONFIG_STACK_VALIDATION; then objtoolopt=3D"${objtoolopt} --stackval" fi =20 + if is_enabled CONFIG_X86_SMAP; then + objtoolopt=3D"${objtoolopt} --uaccess" + fi + + objtoolopt=3D"${objtoolopt} --lto" fi =20 @@ -139,18 +155,6 @@ objtool_link() =20 if [ -n "${objtoolopt}" ]; then =20 - if is_enabled CONFIG_RETPOLINE; then - objtoolopt=3D"${objtoolopt} --retpoline" - fi - - if is_enabled CONFIG_SLS; then - objtoolopt=3D"${objtoolopt} --sls" - fi - - if is_enabled CONFIG_X86_SMAP; then - objtoolopt=3D"${objtoolopt} --uaccess" - fi - if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt=3D"${objtoolopt} --no-fp" fi diff --git a/scripts/package/builddeb b/scripts/package/builddeb index 91a502bb97e8..67cd420dcf89 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -67,7 +67,7 @@ deploy_kernel_headers () { ) > debian/hdrsrcfiles =20 { - if is_enabled CONFIG_STACK_VALIDATION; then + if is_enabled CONFIG_OBJTOOL; then echo tools/objtool/objtool fi =20 diff --git a/tools/include/linux/objtool.h b/tools/include/linux/objtool.h index 586d35720f13..977d90ba642d 100644 --- a/tools/include/linux/objtool.h +++ b/tools/include/linux/objtool.h @@ -38,7 +38,7 @@ struct unwind_hint { #define UNWIND_HINT_TYPE_REGS_PARTIAL 2 #define UNWIND_HINT_TYPE_FUNC 3 =20 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL =20 #ifndef __ASSEMBLY__ =20 @@ -157,7 +157,7 @@ struct unwind_hint { =20 #endif /* __ASSEMBLY__ */ =20 -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ =20 #ifndef __ASSEMBLY__ =20 @@ -179,6 +179,6 @@ struct unwind_hint { .endm #endif =20 -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ =20 #endif /* _LINUX_OBJTOOL_H */ --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8F36C433EF for ; Wed, 13 Apr 2022 23:21:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238452AbiDMXX3 (ORCPT ); Wed, 13 Apr 2022 19:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239277AbiDMXWl (ORCPT ); Wed, 13 Apr 2022 19:22:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5C02623BCF for ; Wed, 13 Apr 2022 16:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892018; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mxZmUhHhFjqsME70R0S3WFA4slATzlbh3Kd5lEw3AX8=; b=dWUBJKwfFBGkl4P++2Ryx2oJz7BFQ9PSYHXyVAJH2kMrxkEnQo9oNIU6YAdnCaW9SY0/Fz t2B/f24UQ83NulIH2QMJaY3K2J9rcjNVYHs8SpnL+K6F5sUaOzo6NxmHik9FEcz231ysA/ cMTDpKVCyHoaDdeCD7mtFkHjraX/LEM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-530-WJI3u08INW-vYxiq4WR3KA-1; Wed, 13 Apr 2022 19:20:17 -0400 X-MC-Unique: WJI3u08INW-vYxiq4WR3KA-1 Received: by mail-qv1-f71.google.com with SMTP id fw9-20020a056214238900b0043522aa5b81so2972026qvb.21 for ; Wed, 13 Apr 2022 16:20:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mxZmUhHhFjqsME70R0S3WFA4slATzlbh3Kd5lEw3AX8=; b=557GZjuuNiGvCmCm7ML1q6vDDaHr2xWYYp8+J0F6elzGC1tY278a0ziU9x7K/TFEFC KZm1Iw9yCvAnJkjStusSsoL8gUCiNmdH8fcTljtafT31wtCIxm63I55twW5ad0k0tuOw d8ZfNhZB/MexVaerR9BzI0ZgnV0BAwFGsZWG+WYZASF/uxNppwfymDrNrRa/DexGNcwf by3LhKzHbM1D2zqbvk+poDq4hQpnpdGgjIosjKqLZEnf+rNXjiK7sSqOpw1cHHC6w3eA g2WqFCXj7iEh1kTF8lk2tt2Ity2atKdQlZbOSinKdoUZWg1lka+36k54BbYBh0CMKaD+ a5Kg== X-Gm-Message-State: AOAM530GnJoNeMYx8LhUAQAQJy9PFJQBNd7sDesdRF0KrIUQl5Cln3YK TrszJMR7d05qJ2lv2uMDzGQnV7HU69KiqktmoWdpvdGBtHcr+ESpqNBCTQK6H7Anl1tKFZ5Tl+l 2m8WS8jJNTVfJwpeKVsZtdcu9 X-Received: by 2002:a05:622a:6115:b0:2f1:d8fa:84aa with SMTP id hg21-20020a05622a611500b002f1d8fa84aamr730199qtb.689.1649892016555; Wed, 13 Apr 2022 16:20:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAitcQonxumnJh9FNiein1nry7WcY5sM/uYLh59j6qEQIt3FSSA0Crgsoe6/42DTBWuyVkbg== X-Received: by 2002:a05:622a:6115:b0:2f1:d8fa:84aa with SMTP id hg21-20020a05622a611500b002f1d8fa84aamr730183qtb.689.1649892016284; Wed, 13 Apr 2022 16:20:16 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:15 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 12/18] objtool: Make stack validation frame-pointer-specific Date: Wed, 13 Apr 2022 16:19:47 -0700 Message-Id: <060241d8a392b079c60d83eef3335a8d45c6b20d.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that CONFIG_STACK_VALIDATION is frame-pointer specific, do the same for the '--stackval' option. Now the '--no-fp' option is redundant and can be removed. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.build | 1 - scripts/link-vmlinux.sh | 4 ---- tools/objtool/builtin-check.c | 3 +-- tools/objtool/check.c | 4 ++-- tools/objtool/include/objtool/builtin.h | 1 - 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0f73e02b7cf1..6eb99cb08821 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -235,7 +235,6 @@ objtool_args =3D \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) =20 cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 5101a7fbfaaf..1be01163a9c5 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -155,10 +155,6 @@ objtool_link() =20 if [ -n "${objtoolopt}" ]; then =20 - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt=3D"${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt=3D"${objtoolopt} --no-unreachable" fi diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index a6a86e2d0598..28bdcffb4267 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -44,7 +44,7 @@ const struct option check_options[] =3D { OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"), OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('S', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), - OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate stack unwinding ru= les"), + OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate frame pointer rule= s"), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), OPT_CALLBACK(0, "dump", NULL, "orc", "dump object data", parse_dumpstr), =20 @@ -54,7 +54,6 @@ const struct option check_options[] =3D { OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"), OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module= "), - OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"), OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable= instruction' warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"), diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 1b1e7a4ae18b..9a6d77a3c5d4 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2807,7 +2807,7 @@ static int update_cfi_state(struct instruction *insn, } =20 /* detect when asm code uses rbp as a scratch register */ - if (!opts.no_fp && insn->func && op->src.reg =3D=3D CFI_BP && + if (opts.stackval && insn->func && op->src.reg =3D=3D CFI_BP && cfa->base !=3D CFI_BP) cfi->bp_scratch =3D true; break; @@ -3285,7 +3285,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (ret) return ret; =20 - if (!opts.no_fp && func && !is_fentry_call(insn) && + if (opts.stackval && func && !is_fentry_call(insn) && !has_valid_stack_frame(&state)) { WARN_FUNC("call without frame pointer save/setup", sec, insn->offset); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index edb0f550727b..ac94db3470d2 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -32,7 +32,6 @@ struct opts { bool dryrun; bool lto; bool module; - bool no_fp; bool no_unreachable; bool stats; bool vmlinux; --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4467C433F5 for ; Wed, 13 Apr 2022 23:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239280AbiDMXXb (ORCPT ); Wed, 13 Apr 2022 19:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239282AbiDMXWn (ORCPT ); Wed, 13 Apr 2022 19:22:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E745237FC for ; Wed, 13 Apr 2022 16:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892019; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KJJ7mXb8AQJ47BJDDLW4QsJJu3BnPE4fGx2ZfDAl8F4=; b=gRzsHYNwWTk8fiEHx2qjAgKxZYYfzRQhIh78W/MvwYmrESmopBVz/unYtUa94pz7cRUL/D IJt8GL1JqnmtnnM+67SZUxy7DftJJMsgQXjQMp/Ma0dxM8c0fCIK8QpifONpGGHf7askhM Ip6ZKke4CwOGqeqWAYGQ2W13rF/dAdU= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-bRld9LkAMlqIU8HvT56oqg-1; Wed, 13 Apr 2022 19:20:18 -0400 X-MC-Unique: bRld9LkAMlqIU8HvT56oqg-1 Received: by mail-qt1-f198.google.com with SMTP id f22-20020ac840d6000000b002dd4d87de21so2204323qtm.23 for ; Wed, 13 Apr 2022 16:20:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KJJ7mXb8AQJ47BJDDLW4QsJJu3BnPE4fGx2ZfDAl8F4=; b=27zg0GKomY/84yM/94Exorezl7LlyH7NIpXgjn4sF2xmjyxVcjNs272czJJlaj0a7M LlBFUrmPt5AHY/NZI0VouWp+XlMvZtU3DtGu7iHFJeMDUGf1G5uE4cmzkfiU1jZWbyXI ea+snwSbEMqSnJ9VPk7oXeXRv5tbtem+O6tE+ZucIp8Vxe+EUiuNM9Ulto4g+L9acU7y xIcXbh5MQCUBubNC+XiXUuz/3ulJRDo2GwSjkSzQsSmB7tlblX1ihhSysCUMY3FVNrF5 B6ZbEJWVh9v9zNv23RR2DrX1T/iDtPrnSU6Wq5KZSZ94d1maGHQGR2NRGAeO3MnkSnJ7 RUiQ== X-Gm-Message-State: AOAM532Gow6P649mY+OoazfemfZgdgylYSssnvvctqBrx9Eq7+BDJNOi fjpHK9Zl1QcmbGBRRCm4YHjGKcNw2NikrTuuCaCOx6M3N29K+h5c1HdTdpgOcYkYHMyhBY565Uz 12ldXeMMWK85ZiMZ626BM+tQM X-Received: by 2002:ac8:5883:0:b0:2e1:c6f9:a12f with SMTP id t3-20020ac85883000000b002e1c6f9a12fmr9057580qta.439.1649892018321; Wed, 13 Apr 2022 16:20:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnszQAoRKzrQqL0TrRhcZ/o4oNBCZgJYWzsaqLjCCjRGpljzm1/kfHtDtMTT+XL4OWnGCRyA== X-Received: by 2002:ac8:5883:0:b0:2e1:c6f9:a12f with SMTP id t3-20020ac85883000000b002e1c6f9a12fmr9057565qta.439.1649892017902; Wed, 13 Apr 2022 16:20:17 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:17 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 13/18] objtool: Add static call cmdline option Date: Wed, 13 Apr 2022 16:19:48 -0700 Message-Id: <3abc167576d593f4f726d614a16f588a63fa7744.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As part of making objtool more modular, put the existing static call code behind a new '--static-call' option. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 5 ++++- tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 10 ++++++---- tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6eb99cb08821..3f20d565733c 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -233,6 +233,7 @@ objtool_args =3D \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ + $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 1be01163a9c5..33f14fe1ddde 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -141,11 +141,14 @@ objtool_link() objtoolopt=3D"${objtoolopt} --stackval" fi =20 + if is_enabled CONFIG_HAVE_STATIC_CALL_INLINE; then + objtoolopt=3D"${objtoolopt} --static-call" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt=3D"${objtoolopt} --uaccess" fi =20 - objtoolopt=3D"${objtoolopt} --lto" fi =20 diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 28bdcffb4267..c663828834e1 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -45,6 +45,7 @@ const struct option check_options[] =3D { OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate ret= poline usage"), OPT_BOOLEAN('S', "sls", &opts.sls, "validate straight-line-speculation mi= tigations"), OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate frame pointer rule= s"), + OPT_BOOLEAN('t', "static-call", &opts.static_call, "annotate static calls= "), OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SM= AP"), OPT_CALLBACK(0, "dump", NULL, "orc", "dump object data", parse_dumpstr), =20 @@ -97,6 +98,7 @@ static bool opts_valid(void) opts.retpoline || opts.sls || opts.stackval || + opts.static_call || opts.uaccess) { if (opts.dump) { fprintf(stderr, "--dump can't be combined with other options\n"); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 9a6d77a3c5d4..511b76aaa6de 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3913,10 +3913,12 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 - ret =3D create_static_call_sections(file); - if (ret < 0) - goto out; - warnings +=3D ret; + if (opts.static_call) { + ret =3D create_static_call_sections(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } =20 if (opts.retpoline) { ret =3D create_retpoline_sites_sections(file); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index ac94db3470d2..6ffa6b5dc276 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -24,6 +24,7 @@ struct opts { bool retpoline; bool sls; bool stackval; + bool static_call; bool uaccess; =20 /* options: */ --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D2F3C433EF for ; Wed, 13 Apr 2022 23:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239369AbiDMXXh (ORCPT ); Wed, 13 Apr 2022 19:23:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239170AbiDMXWp (ORCPT ); Wed, 13 Apr 2022 19:22:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8CA923BF4 for ; Wed, 13 Apr 2022 16:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892022; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w9z8Mm94f59mo8BEOPCdxnOAjEXlHponYE16hwUlryo=; b=IfQcd2eV3GcMs28p/T2hhguD6H2qSRm0k1Xcowh3KsfXNv2eqVoPWZWc9oJcjsU+6B5ME+ nJGoAcHzsnkpvx+7j4W0x2kfJEiJMsTV7gKiBMPWQnBmFfRCTY/iBaKEALywmigrVldfV/ pFDz3eRu3rFhffSi1quLYFfARRLVWNA= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-fPgyQ8j-O5-ABMNOUkYjag-1; Wed, 13 Apr 2022 19:20:21 -0400 X-MC-Unique: fPgyQ8j-O5-ABMNOUkYjag-1 Received: by mail-qv1-f69.google.com with SMTP id e10-20020a0562140d8a00b00443c3595342so3020835qve.8 for ; Wed, 13 Apr 2022 16:20:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w9z8Mm94f59mo8BEOPCdxnOAjEXlHponYE16hwUlryo=; b=DznmWyMuBWJZDFnBtp2qBjCKwdXQltzbeELJwdPgTbUPkvfAptZFB/HFg2P2pbpWKF 1rFmAb9uVGzeiAtDTJKwoqM83P1kYHy9UgHz8sQ+LZPBzmr2YP8YLv0UUm4sjBuaWStP cE4pVwqBT2WuKTCdcSB54YbZQNsygyEHwswOzE22Cu7o/m9VwBTb1VJ9x24d1F/xXLkg RVJi682ifNXKLwDoj3/GI3hF8mX/rfxgkiNV2/U+EwV1wQonEu4mxwzPN5NZxpj2vGed rVWTGjPK4fOEmnQQZvytQJei73es/icRIGTb2JowoIX58w4Y4KWA6wrPNuyn4LImoJm1 b9Nw== X-Gm-Message-State: AOAM532rM1yjSSLYYBCmdD4IuSTv6y7qwb6VKsFOVfYbpgPKFse4muoB XAf4BoDowJ8mb0XtBdNeawbeZ8gbsuR/s/Xb1aKtwk4CkflY03kVyrULaXOUb3fMXPQpq+cOYeN 8Be6xNOruzwq6++FpnzcvonKQ X-Received: by 2002:a37:2756:0:b0:69c:2921:4ec0 with SMTP id n83-20020a372756000000b0069c29214ec0mr8703579qkn.742.1649892019925; Wed, 13 Apr 2022 16:20:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz52++23YGaPLs+LAxSJE6WcX6Rf+1Uj4unAPyGfVcfWUqNnjxRP+4liICOLQwm61C2rIHTuA== X-Received: by 2002:a37:2756:0:b0:69c:2921:4ec0 with SMTP id n83-20020a372756000000b0069c29214ec0mr8703564qkn.742.1649892019609; Wed, 13 Apr 2022 16:20:19 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:19 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 14/18] objtool: Add toolchain hacks cmdline option Date: Wed, 13 Apr 2022 16:19:49 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Objtool secretly does a few awful hacks to overcome toolchain limitations. Make those hacks explicit (and optional for other arches) by associating them with a new '--hacks' cmdline option and corresponding CONFIG_HAVE_TOOLCHAIN_HACKS. Signed-off-by: Josh Poimboeuf --- arch/Kconfig | 4 ++++ arch/x86/Kconfig | 1 + arch/x86/include/asm/jump_label.h | 6 +++--- lib/Kconfig.debug | 4 ++-- lib/Kconfig.kcsan | 4 ++-- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 ++++ tools/objtool/builtin-check.c | 4 +++- tools/objtool/check.c | 4 ++-- tools/objtool/include/objtool/builtin.h | 1 + 10 files changed, 23 insertions(+), 10 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 04cdef16db24..cb5fc88cb996 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1031,6 +1031,10 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT config HAVE_OBJTOOL bool =20 +config HAVE_TOOLCHAIN_HACKS + bool + select OBJTOOL + config HAVE_STACK_VALIDATION bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index bce0c23f3550..410c4e2c7390 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -232,6 +232,7 @@ config X86 select HAVE_MOVE_PUD select HAVE_NMI select HAVE_OBJTOOL if X86_64 + select HAVE_TOOLCHAIN_HACKS if HAVE_OBJTOOL select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_= label.h index 3ce0e67c579c..032434791bf1 100644 --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -20,7 +20,7 @@ _ASM_PTR "%c0 + %c1 - .\n\t" \ ".popsection \n\t" =20 -#ifdef CONFIG_OBJTOOL +#ifdef CONFIG_HAVE_TOOLCHAIN_HACKS =20 static __always_inline bool arch_static_branch(struct static_key *key, boo= l branch) { @@ -34,7 +34,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key *key, bool bran return true; } =20 -#else /* !CONFIG_OBJTOOL */ +#else /* !CONFIG_HAVE_TOOLCHAIN_HACKS */ =20 static __always_inline bool arch_static_branch(struct static_key * const k= ey, const bool branch) { @@ -48,7 +48,7 @@ static __always_inline bool arch_static_branch(struct sta= tic_key * const key, co return true; } =20 -#endif /* CONFIG_OBJTOOL */ +#endif /* CONFIG_HAVE_TOOLCHAIN_HACKS */ =20 static __always_inline bool arch_static_branch_jump(struct static_key * co= nst key, const bool branch) { diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c0e4e47f3ce3..616b93d5db6d 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2036,11 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_TOOLCHAIN_HACKS || \ GCC_VERSION >=3D 120000 || CLANG_VERSION >=3D 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC - select OBJTOOL if HAVE_OBJTOOL + select OBJTOOL if HAVE_TOOLCHAIN_HACKS help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing). diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan index 901c3b509aca..2bdb46354d6a 100644 --- a/lib/Kconfig.kcsan +++ b/lib/Kconfig.kcsan @@ -187,8 +187,8 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >=3D 140000 - select OBJTOOL if HAVE_OBJTOOL + depends on HAVE_TOOLCHAIN_HACKS || CC_IS_GCC || CLANG_VERSION >=3D 140000 + select OBJTOOL if HAVE_TOOLCHAIN_HACKS help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers. diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 3f20d565733c..3b53de3dec67 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -227,6 +227,7 @@ ifdef CONFIG_OBJTOOL objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ + $(if $(CONFIG_HAVE_TOOLCHAIN_HACKS), --hacks) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 33f14fe1ddde..480a49e47fbc 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -117,6 +117,10 @@ objtool_link() # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. =20 + if is_enabled CONFIG_HAVE_TOOLCHAIN_HACKS; then + objtoolopt=3D"${objtoolopt} --hacks" + fi + if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt=3D"${objtoolopt} --ibt" fi diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index c663828834e1..13e1c46f155a 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -38,6 +38,7 @@ static int parse_dumpstr(const struct option *opt, const = char *str, int unset) =20 const struct option check_options[] =3D { OPT_GROUP("Actions:"), + OPT_BOOLEAN('h', "hacks", &opts.hacks, "patch some toolchain bugs/limitat= ions"), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), @@ -91,7 +92,8 @@ int cmd_parse_options(int argc, const char **argv, const = char * const usage[]) =20 static bool opts_valid(void) { - if (opts.ibt || + if (opts.hacks || + opts.ibt || opts.mcount || opts.noinstr || opts.orc || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 511b76aaa6de..273ba6840ed2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1145,7 +1145,7 @@ static void annotate_call_site(struct objtool_file *f= ile, * attribute so they need a little help, NOP out any such calls from * noinstr text. */ - if (insn->sec->noinstr && sym->profiling_func) { + if (opts.hacks && insn->sec->noinstr && sym->profiling_func) { if (reloc) { reloc->type =3D R_NONE; elf_write_reloc(file->elf, reloc); @@ -1593,7 +1593,7 @@ static int handle_jump_alt(struct objtool_file *file, return -1; } =20 - if (special_alt->key_addend & 2) { + if (opts.hacks && special_alt->key_addend & 2) { struct reloc *reloc =3D insn_reloc(file, orig_insn); =20 if (reloc) { diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 6ffa6b5dc276..7bc76edb0a85 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -17,6 +17,7 @@ enum dump { struct opts { /* actions: */ enum dump dump; + bool hacks; bool ibt; bool mcount; bool noinstr; --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D1A9C433F5 for ; Wed, 13 Apr 2022 23:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239251AbiDMXXq (ORCPT ); Wed, 13 Apr 2022 19:23:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239206AbiDMXWq (ORCPT ); Wed, 13 Apr 2022 19:22:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19CC32899F for ; Wed, 13 Apr 2022 16:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892023; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qUjGUDFGqMEo+MVbOZaiIzdIYLW+uz87eKQwOgrZglU=; b=QBBNNp7y3K5gKyx6SnZb8oEq99XLdAGFGXCg1knJGauV6wL7K5Tb7JPbt+AfBQmapSZgyV 9IA3MJsc3bb54bV2+NIOAzNzaqNqHqPv/Le9dhkMHmm+MVmP3mB9da0oC/HA+vvHdX31VV m4Qim9Dz4Y1QSVcRFFGb26Xup8A7lQs= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-537-h3jFYSdAME-tWJtBBo9eig-1; Wed, 13 Apr 2022 19:20:22 -0400 X-MC-Unique: h3jFYSdAME-tWJtBBo9eig-1 Received: by mail-qv1-f72.google.com with SMTP id jz4-20020a0562140e6400b004461f104a7cso1072761qvb.6 for ; Wed, 13 Apr 2022 16:20:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qUjGUDFGqMEo+MVbOZaiIzdIYLW+uz87eKQwOgrZglU=; b=LuV3uWi92jGbtUf4QymbkKqxsskCAFCsuVCa6lPc42oUfKdmx9DYhRVZav6Jpgrs+p OvLgENeJjXVnydmpvo204+jn9PQokkGW53sx8EFXY44BatNOSDVdq3ItbOx+dePm6R57 RLGEuyA03rSMJx7CUPzTLH822kEzoc9F2b50Fq8tYi4QDJfRqXCF5j0CA5GLrgTiBYHB VeFpTWbrh/2iQQwVW3mAEuCUkWeI3tbu+oAGMfKeg1jIFPAp02zC1ILhcYzfXiJRBZYr H2uWhVv4lpNmNW5I1B27naYrD90r3Apgmkc/ckVe4AoF/+RnbWKlDKQEeixdmFQVbxbm YasQ== X-Gm-Message-State: AOAM533lIHHcSYMah9XLiu7WrScQsNtXfvjQaGDzNHo3Tx79Kz40J3yD xulzhTdb6UtHHllwTzE7A1/TrTlYggnPZCV96GNoZ6Y2mxZJRtIQdTbQHIFLkDmODpEE7Ulqnud LeEZZ1hlO9Vhune77SdEuOqJE X-Received: by 2002:ac8:70d8:0:b0:2ef:cee5:b117 with SMTP id g24-20020ac870d8000000b002efcee5b117mr9049865qtp.115.1649892021452; Wed, 13 Apr 2022 16:20:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgkiS+yVYgbKFfVpVm+LB8DEXJ4HafDZjeVew0YcW7PGYdn9Dx4Yt/KMUMTDyBStPOjByEUQ== X-Received: by 2002:ac8:70d8:0:b0:2ef:cee5:b117 with SMTP id g24-20020ac870d8000000b002efcee5b117mr9049857qtp.115.1649892021194; Wed, 13 Apr 2022 16:20:21 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:20 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 15/18] objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION" Date: Wed, 13 Apr 2022 16:19:50 -0700 Message-Id: <8d830d35e1fef33378192ac1a1c6291920618a2f.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" CONFIG_VMLINUX_VALIDATION is just the validation of the "noinstr" rules. That name is a misnomer, because now objtool actually does vmlinux validation for other reasons. Rename CONFIG_VMLINUX_VALIDATION to CONFIG_NOINSTR_VALIDATION. Signed-off-by: Josh Poimboeuf --- include/linux/instrumentation.h | 6 +++--- lib/Kconfig.debug | 2 +- scripts/link-vmlinux.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/instrumentation.h b/include/linux/instrumentatio= n.h index 9111a3704072..bc7babe91b2e 100644 --- a/include/linux/instrumentation.h +++ b/include/linux/instrumentation.h @@ -2,7 +2,7 @@ #ifndef __LINUX_INSTRUMENTATION_H #define __LINUX_INSTRUMENTATION_H =20 -#ifdef CONFIG_VMLINUX_VALIDATION +#ifdef CONFIG_NOINSTR_VALIDATION =20 #include =20 @@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ }) #define instrumentation_end() __instrumentation_end(__COUNTER__) -#else /* !CONFIG_VMLINUX_VALIDATION */ +#else /* !CONFIG_NOINSTR_VALIDATION */ # define instrumentation_begin() do { } while(0) # define instrumentation_end() do { } while(0) -#endif /* CONFIG_VMLINUX_VALIDATION */ +#endif /* CONFIG_NOINSTR_VALIDATION */ =20 #endif /* __LINUX_INSTRUMENTATION_H */ diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 616b93d5db6d..be6ca70d558a 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -500,7 +500,7 @@ config STACK_VALIDATION For more information, see tools/objtool/Documentation/stack-validation.txt. =20 -config VMLINUX_VALIDATION +config NOINSTR_VALIDATION bool depends on HAVE_OBJTOOL && DEBUG_ENTRY select OBJTOOL diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 480a49e47fbc..96dbaaeaecd1 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -156,7 +156,7 @@ objtool_link() objtoolopt=3D"${objtoolopt} --lto" fi =20 - if is_enabled CONFIG_VMLINUX_VALIDATION; then + if is_enabled CONFIG_NOINSTR_VALIDATION; then objtoolopt=3D"${objtoolopt} --noinstr" fi =20 --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FD15C433F5 for ; Wed, 13 Apr 2022 23:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239374AbiDMXXl (ORCPT ); Wed, 13 Apr 2022 19:23:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239266AbiDMXW4 (ORCPT ); Wed, 13 Apr 2022 19:22:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A29FF3A5D1 for ; Wed, 13 Apr 2022 16:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892024; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9TsJJXgMRJcJ5j44p3TeuwPX8JX+llrDTE9XXD7pv2Q=; b=JkDM5o13rbuO2g0e/8WTdfbJaywXQHsO4KzUg422Q3i5zC5+1z1d09+Q19KqnQ1cmX21w/ atGFSWglinclDx+VTC2vk+qXnk5uSwcRTimVOP9X7aLOAvOUUJHVtRoZvPmjCC9cqJXHqP /gN9qmQMCHLvQ3OQyyxvuQIFXz37S4w= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-573-zQHlIR8gOZqQxg5HP-Sh2A-1; Wed, 13 Apr 2022 19:20:23 -0400 X-MC-Unique: zQHlIR8gOZqQxg5HP-Sh2A-1 Received: by mail-qv1-f71.google.com with SMTP id o1-20020a0c9001000000b00440e415a3a2so3000761qvo.13 for ; Wed, 13 Apr 2022 16:20:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9TsJJXgMRJcJ5j44p3TeuwPX8JX+llrDTE9XXD7pv2Q=; b=hg0PFG/vT5gn8qkCmHhjHSZo1v0w3p2mePeJtfKGoVTUv7TlB3RmDW+tStjIQRxZDR dIWi9Jo/5iBerY4kZjtEp9aOgSx1aO/A7uPJbvSVK/I347q0cHJxk8C8CLMAfXnB1Yh2 VGg/gmTz3fZIm04b/CWWghCK2iQnv64dG8YBJNv2q08YwTalNjcozoAzdZmTQ5ykqoQB 8SqzAb1HunFXUr/JlwRWETQlYqeT8hSJx5YwSG07hT46V7rIvXygUtSWF9Ysl939vVGU sey+RVMx6y7x9kegTDa1bkgksyeJn4529QkCmkFdQnaxmW8EVptHebNJrrxHSQeecvSq 9UGg== X-Gm-Message-State: AOAM530cU9cV2SHO3ObMvPFlG5bEE/6YyY/9d9mHLgamRfNxEA78Vl9M 8KoXo3ylZyaKE4t4+p/n+Fs55r3DTndq7aIb9yGCQdm6PBVeeZmI0zEdjoLpzrvSUn0R1BJL/DV v6OhTXXLgoHbscxxBPAmyNUh8 X-Received: by 2002:a05:620a:4055:b0:67d:61ca:e9f2 with SMTP id i21-20020a05620a405500b0067d61cae9f2mr8351278qko.510.1649892022934; Wed, 13 Apr 2022 16:20:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0pFEK1wqpTmd0+kzutwacpYI6JBqcS/3lZ1NkSfSMKTJO/z4tZKaQL9ipfJLew4ZM5sOwcg== X-Received: by 2002:a05:620a:4055:b0:67d:61ca:e9f2 with SMTP id i21-20020a05620a405500b0067d61cae9f2mr8351267qko.510.1649892022713; Wed, 13 Apr 2022 16:20:22 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:22 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 16/18] objtool: Add HAVE_NOINSTR_VALIDATION Date: Wed, 13 Apr 2022 16:19:51 -0700 Message-Id: <94ba30d6e5066fb198f67a477186c89c9cea828e.1649891421.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove CONFIG_NOINSTR_VALIDATION's dependency on HAVE_OBJTOOL, since other arches might want to implement objtool without it. Signed-off-by: Josh Poimboeuf --- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + lib/Kconfig.debug | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index cb5fc88cb996..d0c00564bbf8 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1031,6 +1031,9 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT config HAVE_OBJTOOL bool =20 +config HAVE_NOINSTR_VALIDATION + bool + config HAVE_TOOLCHAIN_HACKS bool select OBJTOOL diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 410c4e2c7390..c73ca72f5d98 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -231,6 +231,7 @@ config X86 select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_NMI + select HAVE_NOINSTR_VALIDATION if HAVE_OBJTOOL select HAVE_OBJTOOL if X86_64 select HAVE_TOOLCHAIN_HACKS if HAVE_OBJTOOL select HAVE_OPTPROBES diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index be6ca70d558a..b5fa86994fd3 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -502,7 +502,7 @@ config STACK_VALIDATION =20 config NOINSTR_VALIDATION bool - depends on HAVE_OBJTOOL && DEBUG_ENTRY + depends on HAVE_NOINSTR_VALIDATION && DEBUG_ENTRY select OBJTOOL default y =20 --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAD2BC433F5 for ; Wed, 13 Apr 2022 23:21:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239344AbiDMXXu (ORCPT ); Wed, 13 Apr 2022 19:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239291AbiDMXW5 (ORCPT ); Wed, 13 Apr 2022 19:22:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 196A44616E for ; Wed, 13 Apr 2022 16:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892026; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xCPwQ1JH76jZXkH9sEaTrRPxjwwIFtJIMBVxZyCU0aI=; b=N0d4bUzqwMJXhcu5HzOQlxOpt4oWa+bGlFXqaQ3HElqw5sriY+RKrVnnKd5OYoDKRer6Pp /V0JrPfbqNXSl7jpyOHhCSaJu7PTE2Mc6/KlPXOXqqsFA5G6kzwr1dpX+38d3hrLueDT4e EnFDgo2UaALRm+rNisMpQP/1nkXZVx0= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-628-BtUqYwr3NmyPcLLu6C6bog-1; Wed, 13 Apr 2022 19:20:25 -0400 X-MC-Unique: BtUqYwr3NmyPcLLu6C6bog-1 Received: by mail-qv1-f70.google.com with SMTP id dd5-20020ad45805000000b004461b16d4caso1742526qvb.16 for ; Wed, 13 Apr 2022 16:20:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xCPwQ1JH76jZXkH9sEaTrRPxjwwIFtJIMBVxZyCU0aI=; b=b3gMWVoTuAx5g6bu8qq0iCKQ6pF1W9dFQLz+AFwTVW3OSfESs15Fw68CMj8uV0UtCk umA7gkffBmRJXAgehcfdAwKHOVPEReEefTCv9LS60LOVZcv8DY9dllxLX9epW6D7D6j3 SsxO92fw6t/b2W/XsPweWHurLo0eFiFHZVg+u3JCuhVPtJUpaEUT0pc3lWOu6VLE2O3h nGrCU3YbRa32hflcbV0Ww9f41FZta7NXgf0mVqFA3TczMMB8ie5row8LuaW1vVGm2Fpe ztCZjfR36aw+OB6zLPllrBkI/8td5Y+HkYNV4VVS4eggeWvy2aYSIdzjc4stBT9SXzOK KI1Q== X-Gm-Message-State: AOAM533laZNmwLvUR9D70/D3eFWhfgVdA4a2hUlhHH6Jd8FUm41WRi5+ BBoAMATqNAfUoLhDZ4d+gORlfnEcaAliwoqdB0RH1Z6gVA04B1hoEFu5vK4FBOxJzJo9MtEG9WD TxaEhU3qYM2TDc3JhYGqutqAc X-Received: by 2002:a05:6214:ccb:b0:444:4af0:bcc7 with SMTP id 11-20020a0562140ccb00b004444af0bcc7mr1056462qvx.126.1649892024524; Wed, 13 Apr 2022 16:20:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyecvQTxqObZtXeJYCZv6oGl6HfNMzGACZiCJ7+Tq0la9Qr+4YZU6YO43idj+Zr4if0YRiFzQ== X-Received: by 2002:a05:6214:ccb:b0:444:4af0:bcc7 with SMTP id 11-20020a0562140ccb00b004444af0bcc7mr1056444qvx.126.1649892024191; Wed, 13 Apr 2022 16:20:24 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:23 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 17/18] objtool: Remove --lto and --vmlinux Date: Wed, 13 Apr 2022 16:19:52 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The '--lto' option is a confusing way of telling objtool to do stack validation despite it being a linked object. That's no longer needed now that an explicit '--stackval' option exists. The '--vmlinux' option can also be made redundant by adding detection of a multi-object archive. Remove both options. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 8 ++--- tools/objtool/builtin-check.c | 23 ++++++++++++-- tools/objtool/check.c | 40 +++++++++---------------- tools/objtool/elf.c | 3 ++ tools/objtool/include/objtool/builtin.h | 2 -- tools/objtool/include/objtool/elf.h | 8 ++++- 7 files changed, 48 insertions(+), 38 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 3b53de3dec67..f4b44d77e8a0 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -228,7 +228,7 @@ objtool :=3D $(objtree)/tools/objtool/objtool =20 objtool_args =3D \ $(if $(CONFIG_HAVE_TOOLCHAIN_HACKS), --hacks) \ - $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ + $(if $(CONFIG_X86_KERNEL_IBT), --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 96dbaaeaecd1..0a79f80bd789 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -114,8 +114,8 @@ objtool_link() =20 if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then =20 - # Don't perform vmlinux validation unless explicitly requested, - # but run objtool on vmlinux.o now that we have an object file. + # For LTO and IBT, objtool doesn't run on individual + # translation units. Run everything on vmlinux instead. =20 if is_enabled CONFIG_HAVE_TOOLCHAIN_HACKS; then objtoolopt=3D"${objtoolopt} --hacks" @@ -152,8 +152,6 @@ objtool_link() if is_enabled CONFIG_X86_SMAP; then objtoolopt=3D"${objtoolopt} --uaccess" fi - - objtoolopt=3D"${objtoolopt} --lto" fi =20 if is_enabled CONFIG_NOINSTR_VALIDATION; then @@ -166,8 +164,6 @@ objtool_link() objtoolopt=3D"${objtoolopt} --no-unreachable" fi =20 - objtoolopt=3D"${objtoolopt} --vmlinux" - info OBJTOOL ${1} tools/objtool/objtool ${objtoolopt} ${1} fi diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 13e1c46f155a..80fc0d1c0a53 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -54,11 +54,9 @@ const struct option check_options[] =3D { OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"), OPT_BOOLEAN(0, "backup", &opts.backup, "create .orig files before modific= ation"), OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), - OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"), OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module= "), OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable= instruction' warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), - OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"), =20 OPT_END(), }; @@ -117,6 +115,24 @@ static bool opts_valid(void) return false; } =20 +static bool link_opts_valid(struct objtool_file *file) +{ + if (is_linked_object(file->elf)) + return true; + + if (opts.noinstr) { + fprintf(stderr, "--noinstr requires linked object\n"); + return false; + } + + if (opts.ibt) { + fprintf(stderr, "--ibt requires linked object\n"); + return false; + } + + return true; +} + int objtool_run(int argc, const char **argv) { const char *objname; @@ -136,6 +152,9 @@ int objtool_run(int argc, const char **argv) if (!file) return 1; =20 + if (!link_opts_valid(file)) + return 1; + ret =3D check(file); if (ret) return ret; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 273ba6840ed2..2d18f23a895b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -264,7 +264,8 @@ static void init_cfi_state(struct cfi_state *cfi) cfi->drap_offset =3D -1; } =20 -static void init_insn_state(struct insn_state *state, struct section *sec) +static void init_insn_state(struct objtool_file *file, struct insn_state *= state, + struct section *sec) { memset(state, 0, sizeof(*state)); init_cfi_state(&state->cfi); @@ -274,7 +275,7 @@ static void init_insn_state(struct insn_state *state, s= truct section *sec) * not correctly determine insn->call_dest->sec (external symbols do * not have a section). */ - if (opts.vmlinux && opts.noinstr && sec) + if (is_linked_object(file->elf) && opts.noinstr && sec) state->noinstr =3D sec->noinstr; } =20 @@ -3418,7 +3419,7 @@ static int validate_unwind_hints(struct objtool_file = *file, struct section *sec) if (!file->hints) return 0; =20 - init_insn_state(&state, sec); + init_insn_state(file, &state, sec); =20 if (sec) { insn =3D find_insn(file, sec, 0); @@ -3504,14 +3505,14 @@ static bool ignore_unreachable_insn(struct objtool_= file *file, struct instructio return true; =20 /* - * Whole archive runs might encounder dead code from weak symbols. + * Whole archive runs might encounter dead code from weak symbols. * This is where the linker will have dropped the weak symbol in * favour of a regular symbol, but leaves the code in place. * * In this case we'll find a piece of code (whole function) that is not * covered by a !section symbol. Ignore them. */ - if (!insn->func && opts.lto) { + if (!insn->func && is_linked_object(file->elf)) { int size =3D find_symbol_hole_containing(insn->sec, insn->offset); unsigned long end =3D insn->offset + size; =20 @@ -3633,7 +3634,7 @@ static int validate_section(struct objtool_file *file= , struct section *sec) if (func->type !=3D STT_FUNC) continue; =20 - init_insn_state(&state, sec); + init_insn_state(file, &state, sec); set_func_state(&state.cfi); =20 warnings +=3D validate_symbol(file, sec, func, &state); @@ -3642,7 +3643,7 @@ static int validate_section(struct objtool_file *file= , struct section *sec) return warnings; } =20 -static int validate_vmlinux_functions(struct objtool_file *file) +static int validate_noinstr_sections(struct objtool_file *file) { struct section *sec; int warnings =3D 0; @@ -3841,16 +3842,6 @@ int check(struct objtool_file *file) { int ret, warnings =3D 0; =20 - if (opts.lto && !(opts.vmlinux || opts.module)) { - fprintf(stderr, "--lto requires: --vmlinux or --module\n"); - return 1; - } - - if (opts.ibt && !opts.lto) { - fprintf(stderr, "--ibt requires: --lto\n"); - return 1; - } - arch_initial_func_cfi_state(&initial_func_cfi); init_cfi_state(&init_cfi); init_cfi_state(&func_cfi); @@ -3871,15 +3862,6 @@ int check(struct objtool_file *file) if (list_empty(&file->insn_list)) goto out; =20 - if (opts.vmlinux && !opts.lto) { - ret =3D validate_vmlinux_functions(file); - if (ret < 0) - goto out; - - warnings +=3D ret; - goto out; - } - if (opts.retpoline) { ret =3D validate_retpoline(file); if (ret < 0) @@ -3904,6 +3886,12 @@ int check(struct objtool_file *file) goto out; warnings +=3D ret; } + + } else if (opts.noinstr) { + ret =3D validate_noinstr_sections(file); + if (ret < 0) + goto out; + warnings +=3D ret; } =20 if (opts.ibt) { diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index f7b2ad27bb1c..41fea838aeba 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -377,6 +377,9 @@ static void elf_add_symbol(struct elf *elf, struct symb= ol *sym) sym->type =3D GELF_ST_TYPE(sym->sym.st_info); sym->bind =3D GELF_ST_BIND(sym->sym.st_info); =20 + if (sym->type =3D=3D STT_FILE) + elf->num_files++; + sym->offset =3D sym->sym.st_value; sym->len =3D sym->sym.st_size; =20 diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 7bc76edb0a85..5c698fb33eca 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -32,11 +32,9 @@ struct opts { bool backtrace; bool backup; bool dryrun; - bool lto; bool module; bool no_unreachable; bool stats; - bool vmlinux; }; =20 extern struct opts opts; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 22ba7e2b816e..1b03a270c58c 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -86,7 +86,7 @@ struct elf { int fd; bool changed; char *name; - unsigned int text_size; + unsigned int text_size, num_files; struct list_head sections; =20 int symbol_bits; @@ -131,6 +131,12 @@ static inline u32 reloc_hash(struct reloc *reloc) return sec_offset_hash(reloc->sec, reloc->offset); } =20 +/* is it a whole archive (vmlinux.o or module)? */ +static inline bool is_linked_object(struct elf *elf) +{ + return elf->num_files > 1; +} + struct elf *elf_open_read(const char *name, int flags); struct section *elf_create_section(struct elf *elf, const char *name, unsi= gned int sh_flags, size_t entsize, int nr); =20 --=20 2.34.1 From nobody Mon May 11 04:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F2B6C433F5 for ; Wed, 13 Apr 2022 23:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239253AbiDMXXx (ORCPT ); Wed, 13 Apr 2022 19:23:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239203AbiDMXW5 (ORCPT ); Wed, 13 Apr 2022 19:22:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 242625640C for ; Wed, 13 Apr 2022 16:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649892027; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ykPgi6kXIPquInV89bqGLiN6dgrVRp+D+st6086CdO8=; b=FZDvE8N6OHxbVz19AzW6yZbRRfNtJF2BU6/I9wewzqnNAgv9sAVX1S0bH6D9cPE1uRbfIX tsDWFUcmfx1mobtNgVle2nJAQh3L3AV7aTHcY56Iy6X7/309QlFVX7pv3w5hi44Awae+3q 9+VTPXglk52rteQbFqY8zv5FP0aaW10= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-T3Va0v85PI2CQa2T4a802Q-1; Wed, 13 Apr 2022 19:20:26 -0400 X-MC-Unique: T3Va0v85PI2CQa2T4a802Q-1 Received: by mail-qt1-f200.google.com with SMTP id o9-20020ac85549000000b002f1d0c8346eso2191298qtr.21 for ; Wed, 13 Apr 2022 16:20:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ykPgi6kXIPquInV89bqGLiN6dgrVRp+D+st6086CdO8=; b=JYYgdFNmjj4YwqRAXmgzvB8JkkLrIsjgxnhJHUqESITB+IO/un1BQkJBg4aAbuaakp 36k6Kj41gcVC34MucTLqaO40n8pk3AqC1PNewfdMMVSz4T8OhlSB5DSC4IbPY8gi6201 Yk2rONFQ/BmMskw6n09VODOIfLGEGfGHOc576dy651i59HUhWHM4a+F5mNDcYALBNg+j lGVT+4BfoipzI1FFg3/xU8wo5CKotZ+/udGV65UjslZW4ZcmMvHj8Nhmauq0/T9va9JM yF9r8iag8gXIU9W6DSuW1sUbk77/rhfApYu5lVpc/hnvhGW8B55KdE4+RuYOdE5elDgw PY7Q== X-Gm-Message-State: AOAM533SpINcZNkMK8tu9/oxFKdWCkp3TZSwI2c/k9PsYdnyB2Xh9xvg FR41nP20sQRcqZQ8hWNZw7tF1Ob7iiIpEI9Kxs/zVTFkWkCfEi1UNh2YOFeKpc96pkUTVVGGZ+Z BCk8PO3byR4c508xECOcYEw+/ X-Received: by 2002:ac8:43cc:0:b0:2eb:dc8a:d5c5 with SMTP id w12-20020ac843cc000000b002ebdc8ad5c5mr9087838qtn.663.1649892025905; Wed, 13 Apr 2022 16:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo9kd0sfypkmA2cvPjqzNpbO8IsWN9VqVvd6yiEJYpM9GU3JlSRzpLqChHQF7LXnpXhkyhBQ== X-Received: by 2002:ac8:43cc:0:b0:2eb:dc8a:d5c5 with SMTP id w12-20020ac843cc000000b002ebdc8ad5c5mr9087822qtn.663.1649892025621; Wed, 13 Apr 2022 16:20:25 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::45]) by smtp.gmail.com with ESMTPSA id b20-20020a05622a021400b002f08f5658a2sm193925qtx.68.2022.04.13.16.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 16:20:25 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 18/18] objtool: Update documentation Date: Wed, 13 Apr 2022 16:19:53 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The objtool documentation is very stack validation centric. Broaden the documentation and describe all the features objtool supports. Signed-off-by: Josh Poimboeuf --- .../{stack-validation.txt =3D> objtool.txt} | 122 +++++++++++++++--- 1 file changed, 102 insertions(+), 20 deletions(-) rename tools/objtool/Documentation/{stack-validation.txt =3D> objtool.txt}= (80%) diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objto= ol/Documentation/objtool.txt similarity index 80% rename from tools/objtool/Documentation/stack-validation.txt rename to tools/objtool/Documentation/objtool.txt index 30f38fdc0d56..8a671902a187 100644 --- a/tools/objtool/Documentation/stack-validation.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -1,15 +1,103 @@ -Compile-time stack metadata validation -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Objtool +=3D=3D=3D=3D=3D=3D=3D =20 +The kernel CONFIG_OBJTOOL option enables a host tool named 'objtool' +which runs at compile time. It can do various validations and +transformations on .o files. =20 -Overview +Objtool has become an integral part of the x86-64 kernel toolchain. The +kernel depends on it for a variety of security and performance features +(and other types of features as well). + + +Features -------- =20 -The kernel CONFIG_STACK_VALIDATION option enables a host tool named -objtool which runs at compile time. It has a "check" subcommand which -analyzes every .o file and ensures the validity of its stack metadata. -It enforces a set of rules on asm code and C inline assembly code so -that stack traces can be reliable. +Objtool has the following features: + +- Stack unwinding metadata validation -- useful for helping to ensure + stack traces are reliable for live patching + +- ORC unwinder metadata generation -- a faster and more precise + alternative to frame pointer based unwinding + +- Retpoline validation -- ensures that all indirect calls go through + retpoline thunks, for Spectre v2 mitigations + +- Retpoline call site annotation -- annotates all retpoline thunk call + sites, enabling the kernel to patch them inline, to prevent "thunk + funneling" for both security and performance reasons + +- Non-instrumentation validation -- validates non-instrumentable + ("noinstr") code rules, preventing instrumentation in low-level C + entry code + +- Static call annotation -- annotates static call sites, enabling the + kernel to implement inline static calls, a faster alternative to some + indirect branches + +- Uaccess validation -- validates uaccess rules for a proper + implementation of Supervisor Mode Access Protection (SMAP) + +- Straight Line Speculation validation -- validates certain SLS + mitigations + +- Indirect Branch Tracking validation -- validates Intel CET IBT rules + to ensure that all functions referenced by function pointers have + corresponding ENDBR instructions + +- Indirect Branch Tracking annotation -- annotates unused ENDBR + instruction sites, enabling the kernel to "seal" them (replace them + with NOPs) to further harden IBT + +- Function entry annotation -- annotates function entries, enabling + kernel function tracing + +- Other toolchain hacks which will go unmentioned at this time... + +Each feature can be enabled individually or in combination using the +objtool cmdline. + + +Objects +------- + +Typically, objtool runs on every translation unit (TU, aka ".o file") in +the kernel. If a TU is part of a kernel module, the '--module' option +is added. + +However: + +- If noinstr validation is enabled, it also runs on vmlinux.o, with all + options removed and '--noinstr' added. + +- If IBT or LTO is enabled, it doesn't run on TUs at all. Instead it + runs on vmlinux.o and linked modules, with all options. + +In summary: + + A) Legacy mode: + TU: objtool [--module] + vmlinux: N/A + module: N/A + + B) CONFIG_NOINSTR_VALIDATION=3Dy && !(CONFIG_X86_KERNEL_IBT=3Dy || CONFI= G_LTO=3Dy): + TU: objtool [--module] // no --noinstr + vmlinux: objtool --noinstr // other options removed + module: N/A + + C) CONFIG_X86_KERNEL_IBT=3Dy || CONFIG_LTO=3Dy: + TU: N/A + vmlinux: objtool --noinstr + module: objtool --module --noinstr + + +Stack validation +---------------- + +Objtool's stack validation feature analyzes every .o file and ensures +the validity of its stack metadata. It enforces a set of rules on asm +code and C inline assembly code so that stack traces can be reliable. =20 For each function, it recursively follows all possible code paths and validates the correct frame pointer state at each instruction. @@ -20,14 +108,6 @@ alternative execution paths to a given instruction (or = set of instructions). Similarly, it knows how to follow switch statements, for which gcc sometimes uses jump tables. =20 -(Objtool also has an 'orc generate' subcommand which generates debuginfo -for the ORC unwinder. See Documentation/x86/orc-unwinder.rst in the -kernel tree for more details.) - - -Why do we need stack metadata validation? ------------------------------------------ - Here are some of the benefits of validating stack metadata: =20 a) More reliable stack traces for frame pointer enabled kernels @@ -113,9 +193,6 @@ c) Higher live patching compatibility rate For more details, see the livepatch documentation in the Linux kernel source tree at Documentation/livepatch/livepatch.rst. =20 -Rules ------ - To achieve the validation, objtool enforces the following rules: =20 1. Each callable function must be annotated as such with the ELF @@ -177,7 +254,8 @@ Another possible cause for errors in C code is if the M= akefile removes -fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options. =20 Here are some examples of common warnings reported by objtool, what -they mean, and suggestions for how to fix them. +they mean, and suggestions for how to fix them. When in doubt, ping +the objtool maintainers. =20 =20 1. file.o: warning: objtool: func()+0x128: call without frame pointer save= /setup @@ -358,3 +436,7 @@ ignore it: OBJECT_FILES_NON_STANDARD :=3D y =20 to the Makefile. + +NOTE: OBJECT_FILES_NON_STANDARD doesn't work for link time validation of +vmlinux.o or a linked module. So it should only be used for files which +aren't linked into vmlinux or a module. --=20 2.34.1