From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8KnYGMfopGpZtQIAWB0awg (envelope-from ) for ; Sat, 12 Sep 2026 01:53:11 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=yoKv24Fo; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 53B6E1E09E; Sat, 12 Sep 2026 01:53:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4BD321E091 for ; Sat, 12 Sep 2026 01:53:10 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C752C48FBC8A for ; Sat, 12 Sep 2026 05:53:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C752C48FBC8A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=yoKv24Fo Received: from mail-vs2-x10.google.com (mail-vs2-x10.google.com [IPv6:2a00:1450:4864:3a::10]) by sourceware.org (Postfix) with ESMTPS id DC12F4900323 for ; Sat, 12 Sep 2026 05:52:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC12F4900323 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DC12F4900323 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:3a::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789192364; cv=none; b=l02wPgeOClMlZiQGNN8/cvxm8myzEuq2Ht4V+Ts+W9PcPl+1mCjzOc0mn18SFzJVpoZXSpgi3iaXup3DL3dpRYVpmhj0mb5v2MQdmQyd6Fuyo19vGBt7Yw1Gxo/UtWTA36wlAFHyl35bT0pjJPOfXlZW8e26LAX01ElGb+cXYPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789192364; c=relaxed/simple; bh=pGMoa+xZALuMZgTLbr/qxQxwwo7HPIEAVIlw3/qV7D8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l8OXG1LIULwCLQ3YfTfdTozABKjLBwhpEFfvl4CM0qGOXbXbl1zhIqWjPrhfDeEywhv/XULpE66TFKlEkdvdUXFwN6fzhDiKq4nGCQs99Yx0hnFwl4KIf/CIX/3tszIa3qS92Yz9P51Hrm3ftNQ455/6hHdoqtVWQ1uh1KgzTdg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=yoKv24Fo DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC12F4900323 Received: by mail-vs2-x10.google.com with SMTP id ada2fe7eead31-78a7003f9f5so568286137.1 for ; Fri, 11 Sep 2026 22:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789192363; x=1789797163; darn=sourceware.org; h=content-type:mime-version:message-id:date:user-agent:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=usnQJl9t1y79FEMMaAONTDVnieXgSSDgGvJdyUixoJQ=; b=yoKv24FolcyoStwXfTL82bm5GoBxYUUF0/iMJ99rWTb1n4pmWPG9w/hdAVXgSe2+tG s2LYkL2K69cFSgOBbkoHe/MWgJTknm9Cp174UMwFjRaqFRyuiCb0iSnXYx6DdMel+BG4 x+LIgbRpvQ4KyyDOZKD8fFIWhPob9rrTB3mrZfWGfTbg1SDmra7JZy74dgPxS85mu+rP T6ZC/eW9eML4iGEKarrrCS9/+5Ap9QDjRFLx29y/FPQT9Zgbmi+RIFh/g0iJ1P7oy9kB v4Mbrz26ISaW1W2Ra8+YWaRbS3/Nqo0izaWDA8bklaNZHB+rL0z/FVB9QbJGiQYbhio3 31Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789192363; x=1789797163; h=content-type:mime-version:message-id:date:user-agent:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=usnQJl9t1y79FEMMaAONTDVnieXgSSDgGvJdyUixoJQ=; b=hgIXLKaBRrhpC5+x1UIuOMsaS2EWCbwZWbfNbT0eYXHk9f4ykavP6h4ESicwFRrgkE SNbnIlYD13xsBdmskskQCCxufA8Bj6TlcVD5ClnzCME/g7mJz4jSB9EOLrUk/QV1jNcG pq1qTcqV8z0CQmnDPcxyc9tR9PQUi2E0wF2rLsoSV85RXYehI5ooiBcQOFhx334zvUsL 9T2awdTxfVuVmpb4CVaihxDoYMx6C0EOd5DsNO8S9de7HRhKotVUAEGuLCa/DhNPuXRG j4+61w1AsVSubWJL3t+cB+pjo5GJjYxndqq71m9xvScWFtEXSzKF3UrWfEp/Kuz8RsDX fY2A== X-Gm-Message-State: AFuF++n7gYA3+1UrRE1IjladfwpIZTHq87F80YJDFXjq1KGLkN+dFeoB mHVxxPbdsKMrc85TSp05yCU8kcNmWAefXy6CHttfcnRU98yisghISl28uYLitVGjpb9Ph5TMA1A 1+x2/ X-Gm-Gg: AYBFou3dgyZ6D0PWyvqTff5n7dAfP7v27d7G65SFKO7tTdGEXCggzmgMSMQ+ihSwV2P O0vOHXrkBG6ebi+G7fhO6IQdvdtlLDO4SkfEZrtzoR3XIQLkDTIG5rmY2ZX3dUZu1fcFmdcsXYC PVrHaoZn1q06W9EDSzu8FXxEb6MObBaEjm3HZzeq5nEm2Xy5E9C+ITSLjEuIkjLv9bp1li+lYBu gP98xejOssPNsaaeoC42SyNtNZ63pN3/lAdjwagocbyEYzo9GF+wQOA/lxswKhKMvD3dBWA3Ccr MsNHV9CG/SkRy3/BCJCiwjyFYJxLWpFuQovoFFyhpUDagyLiiVVrcaeac8LJ/JgJJdFG27qWyM0 aS2BAmFCBGgPo7+EYPg0EXhHE9R8SnLX0eosYU43MQfPEmeQMadk3bgt0/qcurD5TMHJ7kXw6p5 eKYwXnNYhF95s5bRhAvxv9GbzfSnRMZ/+5F7p4CE5F8stnTtuLxqvZHyWkIb3xP7TaF5oZIGuV1 zSitqQduA== X-Received: by 2002:a05:6102:508a:b0:778:5bbb:b2d2 with SMTP id ada2fe7eead31-792a9f7a9b0mr4465731137.11.1789192362663; Fri, 11 Sep 2026 22:52:42 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-982ba0c3679sm5371087241.10.2026.09.11.22.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 22:52:41 -0700 (PDT) From: Thiago Jung Bauermann To: "Joos, Christina" Cc: "gdb-patches@sourceware.org" , "tom@tromey.com" Subject: Re: [PATCH v4 08/13] gdb: Add command option 'bt -shadow' to print the shadow stack backtrace. In-Reply-To: (Christina Joos's message of "Thu, 10 Sep 2026 19:36:08 +0000") References: <20260708143639.2214689-1-christina.schimpe@intel.com> <20260708143639.2214689-9-christina.schimpe@intel.com> <878q5iss3f.fsf@linaro.org> User-Agent: mu4e 1.14.3; emacs 30.2 Date: Sat, 12 Sep 2026 05:52:39 +0000 Message-ID: <87mrtnqamw.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hello Christina, "Joos, Christina" writes: >> -----Original Message----- >> From: Thiago Jung Bauermann >> Sent: Donnerstag, 3. September 2026 09:38 >> To: Joos, Christina >> Cc: gdb-patches@sourceware.org; tom@tromey.com >> Subject: Re: [PATCH v4 08/13] gdb: Add command option 'bt -shadow' to print >> the shadow stack backtrace. >> >> Christina Schimpe writes: >> >> > +/* If possible, get shadow stack frame info for the shadow stack pointer >> > + SSP and its current frame LEVEL. Pass FALLBACK_ARCH which can be used >> > + as fallback gdbarch in case the gdbarch cannot be extracted from the >> > + SAL. Usually this is the gdbarch of the previous frame. */ >> > + >> > +static std::optional >> > +get_shadow_stack_frame_info >> > + (gdbarch *fallback_arch, const CORE_ADDR ssp, unsigned long level) >> > +{ >> > + CORE_ADDR value; >> > + if (!read_shadow_stack_memory (fallback_arch, ssp, value)) >> > + return {}; >> > + >> > + /* At this point, we know that SSP points to VALUE which is a return >> > + address. In contrast to find_frame_sal which is used for the normal >> > + backtrace command, VALUE always points at the return instruction >> > + (which is *after* the call instruction). Since we want to get the >> > + line containing the call (because the call is where the user thinks >> > + the program is), we pass 1 here as second argument. */ >> > + symtab_and_line sal = find_sal_for_pc (value, 1); struct gdbarch >> > + *sal_arch = get_sal_arch (sal); >> >> Nit: remove unnecessary struct keyword. >> >> Also just FYI I'm encountering a snag here in the case of aarch64, which I'm still >> looking into: >> >> The gdbarch returned by get_sal_arch here doesn't have the shadow stack >> hooks set. This causes "bt -shadow" from a signal handler not to show >> "", because this "simpler" gdbarch will get passed as >> fallback_arch in the next call to get_shadow_stack_frame_info by >> shadow_stack_frame_info::unwind_prev_shadow_stack_frame_info, and then >> gdbarch_is_no_return_shadow_stack_address_p (fallback_arch) will be false >> and the corresponding aarch64 hook won't get a change to identify the >> sigframe token. >> >> I think get_sal_arch is returning a gdbarch that was created before the inferior >> was started, and at that time GDB couldn't know that GCS would be enabled. >> >> In any case, if this is working fine for x86 then don't worry about it. I can fix it >> when posting the aarch64 support for "bt -shadow". > > I don't remember seeing something like this, but I also posted this some time > ago.... Maybe something changed in between in upstream. > Did this happen with a specific linux kernel/OS version or a specific testprogram? > Then I can double check to verify this. This is on Ubuntu 26.04, with a new testcase for GCS that does exactly the same things as gdb.arch/amd64-shadow-stack-backtrace-signal.exp. I had more time to dig into this today. Now understood what's going on and I don't think x86 is affected. The problem is that aarch64_gdbarch_init and aarch64_linux_init_abi only install the shadow stack gdbarch hooks if GCS is enabled. So for a gdbarch initialized before the inferior is running, GDB can't know whether GCS will be enabled or not and the shadow stack gdbarch hooks aren't installed in that gdbarch. This isn't really necessary though because the hooks check at runtime if GCS is enabled and it's harmless to call them on an inferior that doesn't have GCS. If I unconditionally install the shadow stack hooks as the patch at the end of this email does, then everything works fine. One of the changes below would be on patch 2 of this series. I'll reply to it. The other is a local patch I haven't submitted yet. -- Thiago (he/him) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index e2a25086d169..390bec441bf9 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -3229,14 +3229,11 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_use_target_description_from_corefile_notes (gdbarch, aarch64_use_target_description_from_corefile_notes); - if (tdep->has_gcs_linux ()) - { - set_gdbarch_get_shadow_stack_pointer (gdbarch, + set_gdbarch_get_shadow_stack_pointer (gdbarch, aarch64_linux_get_shadow_stack_pointer); - set_gdbarch_is_no_return_shadow_stack_address (gdbarch, - aarch64_linux_is_no_return_shadow_stack_address); - tdep->fn_prev_gcspr = dwarf2_prev_ssp; - } + set_gdbarch_is_no_return_shadow_stack_address (gdbarch, + aarch64_linux_is_no_return_shadow_stack_address); + tdep->fn_prev_gcspr = dwarf2_prev_ssp; } #if GDB_SELF_TEST diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index d789b8569d22..7e16d821ff7c 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -4804,12 +4804,10 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_memtag_to_string (gdbarch, aarch64_memtag_to_string); if (tdep->has_gcs ()) - { - /* AArch64's shadow stack pointer is the GCSPR. */ - set_gdbarch_ssp_regnum (gdbarch, tdep->gcs_reg_base); - set_gdbarch_top_addr_empty_shadow_stack - (gdbarch, aarch64_top_addr_empty_shadow_stack); - } + /* AArch64's shadow stack pointer is the GCSPR. */ + set_gdbarch_ssp_regnum (gdbarch, tdep->gcs_reg_base); + set_gdbarch_top_addr_empty_shadow_stack (gdbarch, + aarch64_top_addr_empty_shadow_stack); /* ABI */ set_gdbarch_short_bit (gdbarch, 16);