Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp41016pxb; Tue, 12 Apr 2022 16:13:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoS/Il4XoVvriTHJ9imuRIDfGeH3wgAKz562kvapotTIhEsO6JTO/jcB//jekpnjzC4ceg X-Received: by 2002:a63:7c06:0:b0:398:31d5:f759 with SMTP id x6-20020a637c06000000b0039831d5f759mr32472210pgc.513.1649805183646; Tue, 12 Apr 2022 16:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649805183; cv=none; d=google.com; s=arc-20160816; b=QPMiuV8jJDaCZvHG1qM0rJ5p6TRr4kem70taL5yLN7Q3Lkw2DehInw0nFRRfmi+Pnq dWidLhWLvVYTljh4Z9ak3T3DKFGKwwpi3CLnq9wuTNGT0/NyMYUwWbe1sLTEtJplMqA0 QNmak9T76rWOo3wvaOLAGoAi233WsEwvR3GFSZazdl0eQOg4w9CkEdKFNJ4qOdhAXGOv xZlZJxj8Mu3OrMDQFI9q5Ef+WE9lpq9pMhG9Ll42nQARwncA23dr9fyRFY3HC1y8LXJe uAa60fcLM0l5GbfL5rXMZQnuUDPs3Dj9aujLm4Uh2ZbOqsymNIPy24yJwfAAVY7fpCLO Ohkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0ZCQd9ke2KAWwc19bl0zzlVfHby01VezJ6qx5ncoRec=; b=aYGI/WdSDABzHX8f8u/okfZgjfhRuCc7su9jl/ao5oMwjBAmzRohJ5wfTSMi2fY0mu RrOdZmn3xwl0qGvuVpTH1BMEXL+HTJfKjlq2lJgrJzx35F1k0XniMg3OlgF60yw1Cn3w eOj/y48gxolpUWvyo0PYvzI7Yl4NQJvBwxSRmYn+AY6xAlZCw1cHuPi+jch9CcOEa9lu 9qCW0f8+lkp1rhVItKku8/RwbFLYoa7m9eWrV5n/BRZUpZbDOW1EF+CbtmRJwe+WaTV+ lblCrKP0fyCkDaQWj6Oql4Pk+/ez81SOWrKzNE9jhewaEpAf4I0/GwxKBqWRSEMh9Zqx hbSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WQIMFIZx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v127-20020a632f85000000b0039ce0b69438si4027240pgv.370.2022.04.12.16.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:13:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WQIMFIZx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A83B312658D; Tue, 12 Apr 2022 14:55:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbiDKXNd (ORCPT + 99 others); Mon, 11 Apr 2022 19:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231752AbiDKXNW (ORCPT ); Mon, 11 Apr 2022 19:13:22 -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 8BFC212ACD for ; Mon, 11 Apr 2022 16:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649718665; 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=0ZCQd9ke2KAWwc19bl0zzlVfHby01VezJ6qx5ncoRec=; b=WQIMFIZxcJN/KX+OdPdpSmYw1iDX3Rgz+/jmZnjPAdpPcM7YTDy60CS7Y9EXlY7vVQO4yp kbvLOg6BYc6d2vdO3UU7hIxC4NjtFiVxiVNGmkhcxjYRsgELl9SDg5BMyOjeCuOV3aLdNc Jr3iL8SkeBWoa/N5dUxFCDJsPOzgps4= 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-184-_SeYdMwzN0ubioKLE2ifIA-1; Mon, 11 Apr 2022 19:11:04 -0400 X-MC-Unique: _SeYdMwzN0ubioKLE2ifIA-1 Received: by mail-qv1-f69.google.com with SMTP id ke15-20020a056214300f00b00443efe3fe65so16908304qvb.14 for ; Mon, 11 Apr 2022 16:11: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=0ZCQd9ke2KAWwc19bl0zzlVfHby01VezJ6qx5ncoRec=; b=lNkJnDf0FJ3G7bFwFMbcKnUhSc2b0rOgI7LiE0nmBkFQU8vOiWjwvK7ZK1x3mpgvNK K6KwSde5CgZAREkMo5v+inPjSrNLYo7PZ3ZrR6sh6CggKzPMB9lWBvsmoZl5JM7t3bU+ 0Z4QSpS1Kp1M344PYaqXgA+LMh+KpCmoqNH3BHyZyFYWntdWAiGhB4lputwekhniG51A FPqwtXNbxO9ANJophKZJPF5Akr5nzeMhlGh6pLqjMEZ/04G/jQUz392GKQBEXYRd2lBu tfzlQ7OsgTw2fO9/jIznutiBJNyyn+77PPteHaA5vt4ddxXJHxDUvcTepoVGEPVtIeBk DzvQ== X-Gm-Message-State: AOAM531O3exl+a6NLx7Ne1hfpcF859i8WUTebGxgR5JyXjWO3L6qm/vE HqDUG1dJ7auUBejVXfrao6LDAIAoCG4HJXsnbA7tJnrkbP6fMN/xTiagUpYtao4Pg47YguVIReX THlJtgbDjcW1nnJT7O4G2LVEu X-Received: by 2002:ac8:4c9a:0:b0:2ed:f0a:77c4 with SMTP id j26-20020ac84c9a000000b002ed0f0a77c4mr1350331qtv.376.1649718663874; Mon, 11 Apr 2022 16:11:03 -0700 (PDT) X-Received: by 2002:ac8:4c9a:0:b0:2ed:f0a:77c4 with SMTP id j26-20020ac84c9a000000b002ed0f0a77c4mr1350318qtv.376.1649718663554; Mon, 11 Apr 2022 16:11:03 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id c3-20020ac87d83000000b002e1d1b3df15sm27243500qtd.44.2022.04.11.16.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 16:11:03 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] objtool: Fix sibling call detection in alternatives Date: Mon, 11 Apr 2022 16:10:31 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In add_jump_destinations(), sibling call detection requires 'insn->func' to be valid. But alternative instructions get their 'func' set in handle_group_alt(), which runs *after* add_jump_destinations(). So sibling calls in alternatives code don't get properly detected. Fix that by changing the initialization order: call add_special_section_alts() *before* add_jump_destinations(). This also means the special case for a missing 'jump_dest' in add_jump_destinations() can be removed, as it has already been dealt with. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 6f492789c8c0..0f5d3de30e0d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1277,6 +1277,13 @@ static int add_jump_destinations(struct objtool_file *file) unsigned long dest_off; for_each_insn(file, insn) { + if (insn->jump_dest) { + /* + * handle_group_alt() may have previously set + * 'jump_dest' for some alternatives. + */ + continue; + } if (!is_static_jump(insn)) continue; @@ -1308,15 +1315,6 @@ static int add_jump_destinations(struct objtool_file *file) jump_dest = find_insn(file, dest_sec, dest_off); if (!jump_dest) { - - /* - * This is a special case where an alt instruction - * jumps past the end of the section. These are - * handled later in handle_group_alt(). - */ - if (!strcmp(insn->sec->name, ".altinstr_replacement")) - continue; - WARN_FUNC("can't find jump dest instruction at %s+0x%lx", insn->sec, insn->offset, dest_sec->name, dest_off); @@ -1549,13 +1547,13 @@ static int handle_group_alt(struct objtool_file *file, continue; dest_off = arch_jump_destination(insn); - if (dest_off == special_alt->new_off + special_alt->new_len) + if (dest_off == special_alt->new_off + special_alt->new_len) { insn->jump_dest = next_insn_same_sec(file, last_orig_insn); - - if (!insn->jump_dest) { - WARN_FUNC("can't find alternative jump destination", - insn->sec, insn->offset); - return -1; + if (!insn->jump_dest) { + WARN_FUNC("can't find alternative jump destination", + insn->sec, insn->offset); + return -1; + } } } @@ -2254,14 +2252,14 @@ static int decode_sections(struct objtool_file *file) return ret; /* - * Must be before add_special_section_alts() as that depends on - * jump_dest being set. + * Must be before add_jump_destinations(), which depends on 'func' + * being set for alternatives, to enable proper sibling call detection. */ - ret = add_jump_destinations(file); + ret = add_special_section_alts(file); if (ret) return ret; - ret = add_special_section_alts(file); + ret = add_jump_destinations(file); if (ret) return ret; -- 2.34.1