Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4186170rwe; Mon, 17 Apr 2023 09:04:59 -0700 (PDT) X-Google-Smtp-Source: AKy350bhMZelGnunJfx7/vdhn+iaxu0yjQhXHvxL/+2Hv9KE+xLRNrz0grqgiLgyrwAsG8CjGmhN X-Received: by 2002:a17:902:f10c:b0:1a6:91f0:f7fd with SMTP id e12-20020a170902f10c00b001a691f0f7fdmr6823870plb.60.1681747498861; Mon, 17 Apr 2023 09:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681747498; cv=none; d=google.com; s=arc-20160816; b=fw4R8vv5RVW8QiL0k2FakH6WWHWw3iAcGQI86+DAMa8m+ByL2XgvJW6LItZopJhoFg RckQdeHmWNkC6hF3TSwCRjIQvt39cn2W+q2BU1kqO6siUoMCigBZ0Oo9Bf4roEpeboXR 9fZVm3sw1dPe8JfXOx+O+THosGoAQjjGfOQj4L9AMxe4fT67ZE0SEowjNpQZZOKEplhX 8N4hEOeshrSNZDqboX1IgCG402mOeU+DQ1D/nQy8mNSEKybLC4b/b/5XsDP8OIPzuZPf Rr7b8Y9mjDkQMqdSIGW1Xf0GqB5gjjkrw4HRWXE0Zg1D70wNCOP19Cqkb+0DADPBW+Ja fyYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:dkim-signature :from; bh=+Stu6nPzgU0Ai4LxOYVdsHhavq/oPQSefC062JDQG1U=; b=TkRiINvlzJ5L2J21roraARrRya3h1ycEuTkL9xa8NdNAGR2sIF+J+FNq1q+E0Yi2n5 buCS4Uh59QcWFBj9ignbOrl2hlesCy1Vm1k6XWDw9izFToFJ9p+2uZPyr8fez2Y8fF1g NPNbA/BxIR2/Xr4/T/T/x1l7ChTfPzGshSr8HoOYoM2+jHrNdEvo0tlgo4yHRSPtK+XE ohggXRuamlJAgM7QMJ36CMaTA7rPfr/a6ojEfTyaPOOZlLQytvSnJbSfJiVlElna6a0n +cWzDqftgpT/Rhlg6nO3o01DV7VKSHUaO8fF3mwNAGVkVFM5HWmcP2IZmI6ZczJn6VGc jP/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=hzQwJo69; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020a170902900500b001a23bf7a7b9si9743097plp.501.2023.04.17.09.04.16; Mon, 17 Apr 2023 09:04:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=hzQwJo69; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230501AbjDQQCH (ORCPT + 99 others); Mon, 17 Apr 2023 12:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230137AbjDQQBx (ORCPT ); Mon, 17 Apr 2023 12:01:53 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EC76C17B; Mon, 17 Apr 2023 09:01:43 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1681747301; bh=9096Axbwkb5RULpEWmhmqDxDTfhtR94gJcnvpcVYljc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hzQwJo69/eMSqc5dq85JLzKI3yUdHw/NvcRfp8mtuU+HYH1DFKD6Xdxi6JDWeqi8M AUGR54oBJ7UV7UKIiwWHjFfYlHq0d7lmJgl8YZYVyuQP3CBBu0UU5tWsY8KbX+m9pj QlwCFb9z0YOB/U7zSNrt6kTyXZKtCVG4sL9bQI0c= Date: Mon, 17 Apr 2023 18:01:32 +0200 Subject: [PATCH 2/6] tools/nolibc: riscv: add stackprotector support MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20230408-nolibc-stackprotector-archs-v1-2-271f5c859c71@weissschuh.net> References: <20230408-nolibc-stackprotector-archs-v1-0-271f5c859c71@weissschuh.net> In-Reply-To: <20230408-nolibc-stackprotector-archs-v1-0-271f5c859c71@weissschuh.net> To: Willy Tarreau , Shuah Khan , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1681747300; l=1984; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=9096Axbwkb5RULpEWmhmqDxDTfhtR94gJcnvpcVYljc=; b=G2kyIfSoKVPBz/GbvVu4K6RodfnUF9UYUpy4/vKKzawGKD6LgcM4U5ANPLBC+L0xsG5FO0iA0 a4UzdbTWSHsBeIc6cRypowKluMPEQ5m7M6apMZsDwFnowwAP53abYcF X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/arch-riscv.h | 7 ++++++- tools/testing/selftests/nolibc/Makefile | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index 0d5f15fdedc4..b2ccffcc079f 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -173,14 +173,19 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); +#define __ARCH_SUPPORTS_STACK_PROTECTOR + /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_protector)) _start(void) { __asm__ volatile ( ".option push\n" ".option norelax\n" "lla gp, __global_pointer$\n" ".option pop\n" +#ifdef NOLIBC_STACKPROTECTOR + "call __stack_chk_init\n" /* initialize stack protector */ +#endif "lw a0, 0(sp)\n" /* argc (a0) was in the stack */ "add a1, sp, "SZREG"\n" /* argv (a1) = sp */ "slli a2, a0, "PTRLOG"\n" /* envp (a2) = SZREG*argc ... */ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 3c8e3a6f8985..0a83ad388a16 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -82,6 +82,7 @@ CFLAGS_STACKPROTECTOR = -DNOLIBC_STACKPROTECTOR \ CFLAGS_STKP_i386 = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86_64 = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86 = $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_riscv = $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 = -m64 CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \ $(call cc-option,-fno-stack-protector) \ -- 2.40.0