From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A50B2EB874 for ; Thu, 4 Sep 2025 22:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757025558; cv=none; b=UDjBQCNOCQ+2whNxtxYXIoYpTu2oDKZPV2c9hYpm9pHbwe7djI1E3CwP/8jyJFswDOqm+lX8yv52gTy3Ed/LwRUUUmjRTvi9lGgYU94qGlmVqWh8lI5BVipdbq61JuIienquFgErDeAXbYUWnf9bJYhCDEkoceoMjAhu5pahcNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757025558; c=relaxed/simple; bh=wpukPNGidBsZHZNBLMBXDHyt6toluvhOIdHF3dHictg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=L6RSQeSQGrbTQW88BexYQz917/Kdx8EPiiPbQMw47N5TE+F+ZtLanexapjQ5wBQsaArQQ2MV90x1333NN/nuQ5bJ368sBXBTVaJCxWRun4NmG2OtfcWiCfhKAU5fll8hiOMdIOBKBNCYciHBek9QTR01YguHPeqFU3vKBKOOQzg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dylanbhatch.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=163Ify+g; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dylanbhatch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="163Ify+g" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-32bbacf6512so609056a91.1 for ; Thu, 04 Sep 2025 15:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757025556; x=1757630356; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dtLRBEibPgJC5DKIIcXUNvr0Jg7QinxVii68wLCzhSQ=; b=163Ify+gfyn1wSrYZp09DmS6Dtd6P7WBgRZm4X+uYyeu4jjUd2RVh5zfuUPIeGqQqh f+pWy28ip4QrPdmeeTnL5mdnSi05jErXKwivHopLmqRw0lp2z3c5L9t3ouDX53BJpO2S niZ9K4PUOf/WUw1BhcBFdxO3xpdOYjgfRgyS5aFgifybIQK8HIg2X+MpVaSAe9pCjK6o 6Pu2tqfq6RpnO0zcF+1VFV/8ogOVKwLQ9DFQgKwR3/bxE/zP3MCOq6yxsmyagBWjEYBM 3aMn2nwsKsOEf4rIA0mwuS4v38TAXdE9vU+c+mKVmu0rV6kGL0CFzp0HzDTzwMrs5c8b LcaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757025556; x=1757630356; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dtLRBEibPgJC5DKIIcXUNvr0Jg7QinxVii68wLCzhSQ=; b=PFimmJrOMQ178wpx71iqUBfxGGdWmDWZHfODCwNIZ5g/3QPabUoRodrTuMThsCjUL2 uGJugz7ejnBtL7Gyj/p/Yfcg2NbzDkO9ASv54Z3zSgWusk3gfSWoaSWstRz/qngMRe7J XCU+by6gNZPjQUsRPjCtPI1XzAYF2O4nXnN4HosbgZpzz89F5w5HxYp8vNWX+C/qkEEq nE2VywS7u0ZgNlFiiBHhd+yS7ZlWpNe23OVi7ogzV5Qi9AK7u/QXD3XBUfUjnkGqRyHw 3VbFKBLz5dGg2GIvAPRIh0FG/fHKZRXZPK+nnRlJORj0iGR8yAv3fN4W5JoR9JBIll9A DGuw== X-Forwarded-Encrypted: i=1; AJvYcCUlKyAdt0S8kdVmb4XSQmH+pFFggqEGSHiBuAMtQWehvxJ/a9ioxknLgve1LNCwAKyPe5dnltoaLwrRnA3Ac/mW@vger.kernel.org X-Gm-Message-State: AOJu0YxVduerk8xT4klKWwbAjNwcJyebjuumsFu03DQ5jNYTZUXj47sz QLlwEmwRZPgneOMle1CRh6pTyIbxMFoKauPPPxR41OapSDtgwfRkCSqB9YBq5Gb0/eF+Qf6W8Ly 1TrxWHboq3vBTNI3ygqpGrDu82w== X-Google-Smtp-Source: AGHT+IGXLPNA47OzrNlwR+6Ds93TCeSbcveB/7SH+UNLQts5VBH9tcTynj2fUKqKY9GmrReRRyDIXA2CAA/pnv5LGQ== X-Received: from pjl11.prod.google.com ([2002:a17:90b:2f8b:b0:329:d09b:a3f2]) (user=dylanbhatch job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3905:b0:32b:8b8d:c2af with SMTP id 98e67ed59e1d1-32b8b8dc8e4mr6542460a91.9.1757025555612; Thu, 04 Sep 2025 15:39:15 -0700 (PDT) Date: Thu, 4 Sep 2025 22:38:45 +0000 In-Reply-To: <20250904223850.884188-1-dylanbhatch@google.com> Precedence: bulk X-Mailing-List: linux-toolchains@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250904223850.884188-1-dylanbhatch@google.com> X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250904223850.884188-2-dylanbhatch@google.com> Subject: [PATCH v2 1/6] unwind: build kernel with sframe info From: Dylan Hatch To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra , Will Deacon , Catalin Marinas , Jiri Kosina Cc: Dylan Hatch , Roman Gushchin , Weinan Liu , Mark Rutland , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, Puranjay Mohan , Song Liu , Prasanna Kumar T S M Content-Type: text/plain; charset="UTF-8" Use the -Wa,--gsframe flags to build the code, so GAS will generate a new .sframe section for the stack trace information. Currently, the sframe format only supports arm64 and x86_64 architectures. Add this configuration on arm64 to enable sframe unwinder in the future. Signed-off-by: Weinan Liu Signed-off-by: Dylan Hatch Reviewed-by: Prasanna Kumar T S M --- Makefile | 8 ++++++++ arch/Kconfig | 6 ++++++ arch/arm64/Kconfig.debug | 10 ++++++++++ arch/arm64/kernel/vdso/Makefile | 2 +- include/asm-generic/vmlinux.lds.h | 15 +++++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b9c661913250..09972c71a3e8 100644 --- a/Makefile +++ b/Makefile @@ -1078,6 +1078,14 @@ endif # Ensure compilers do not transform certain loops into calls to wcslen() KBUILD_CFLAGS += -fno-builtin-wcslen +# build with sframe table +ifdef CONFIG_SFRAME_UNWIND_TABLE +CC_FLAGS_SFRAME := -Wa,--gsframe +KBUILD_CFLAGS += $(CC_FLAGS_SFRAME) +KBUILD_AFLAGS += $(CC_FLAGS_SFRAME) +export CC_FLAGS_SFRAME +endif + # change __FILE__ to the relative path to the source directory ifdef building_out_of_srctree KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=) diff --git a/arch/Kconfig b/arch/Kconfig index d1b4ffd6e085..4362d2f49d91 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1782,4 +1782,10 @@ config ARCH_WANTS_PRE_LINK_VMLINUX config ARCH_HAS_CPU_ATTACK_VECTORS bool +config AS_SFRAME + def_bool $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc) + +config SFRAME_UNWIND_TABLE + bool + endmenu diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index 265c4461031f..d64bf58457de 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -20,4 +20,14 @@ config ARM64_RELOC_TEST depends on m tristate "Relocation testing module" +config SFRAME_UNWINDER + bool "Sframe unwinder" + depends on AS_SFRAME + depends on 64BIT + select SFRAME_UNWIND_TABLE + help + This option enables the sframe (Simple Frame) unwinder for unwinding + kernel stack traces. It uses unwind table that is directly generated + by toolchain based on DWARF CFI information. + source "drivers/hwtracing/coresight/Kconfig" diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile index 7dec05dd33b7..c60ef921956f 100644 --- a/arch/arm64/kernel/vdso/Makefile +++ b/arch/arm64/kernel/vdso/Makefile @@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index ae2d2359b79e..4f486080e4fb 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -473,6 +473,8 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) *(.rodata1) \ } \ \ + SFRAME \ + \ /* PCI quirks */ \ .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \ BOUNDED_SECTION_PRE_LABEL(.pci_fixup_early, _pci_fixups_early, __start, __end) \ @@ -891,6 +893,19 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) #define TRACEDATA #endif +#ifdef CONFIG_SFRAME_UNWIND_TABLE +#define SFRAME \ + /* sframe */ \ + .sframe : AT(ADDR(.sframe) - LOAD_OFFSET) { \ + __start_sframe_header = .; \ + KEEP(*(.sframe)) \ + KEEP(*(.init.sframe)) \ + __stop_sframe_header = .; \ + } +#else +#define SFRAME +#endif + #ifdef CONFIG_PRINTK_INDEX #define PRINTK_INDEX \ .printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \ -- 2.51.0.355.g5224444f11-goog