Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp317227rwd; Mon, 12 Jun 2023 14:07:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+M3drdrRsefu8thjD9iYSgywJix3Lopdl5bcAKZgMYbjYaWlJVHWSLIPyY9daRfqEujO4 X-Received: by 2002:a50:fb94:0:b0:509:c6e6:c002 with SMTP id e20-20020a50fb94000000b00509c6e6c002mr5192138edq.39.1686604052522; Mon, 12 Jun 2023 14:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686604052; cv=none; d=google.com; s=arc-20160816; b=bVqIwkstf1Wxvph4IilJFtCVPFyX4vX5vaIsGjcIWp36skFqAJA85sGlMEm+IV0ODM ZD6PTtPrDj9RmG9IrO38B3fvbbG7xGUqG69mkG8SCwPPPqseDqzmt0+MBkCQdnGItaM/ JZLcmC6j0qAVKwIHKP+ZKoxRSecCni2/RKI0Dkjk9PB5jJRH4KhmRq3D+PbXXlZv0R30 ukUteUfV6WyEtLk7x2dvynXmZypseWTIhlYiOt/R3miqpYr0KSANKhZbpmOgUhkbGY9X zZoBj0qiYo/1E2SWLtRrJrU4+gJbAWO/KmWU1WYgHRlDIiBASVZiSNjlDK13HpLnPdfs 7u7w== 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=ZUzTwmpp3dEPaayz4bS/3wGTXDvztziEbihneUCoVoI=; b=S3EzxgFd7Z0JdisEmlvEmC68mh+4TGqZXO+URFiY2WNf3ED1HpCvxX10Bz3ccANtv7 TJ1180D2ciuT6rBH8PSrLFlvhw/NAxfFL/LIUoKF/S370i4rsS45lxr40ZZAKw44NPYF eRpqA+3l7BE4aXs1une3iR6n9VG8BhH6o0tfxQWoVv40ptBYNT/jjait67IyVFNSw1SG 5wuqdICSCb99NBAkjHO5WUMLOJrUrflP9knholAUGQ4wNCHIziW3inOLtSFfc8fwTGXD FLRSM0YQlt4zSFwYpSQHJx4cI2AT7KIVEqp4BKx2+mqVntywPDVblP/CHb1adAsUmmB+ QaPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hlX9DSde; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m18-20020aa7c2d2000000b005069976f799si6665981edp.401.2023.06.12.14.07.07; Mon, 12 Jun 2023 14:07:32 -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=@kernel.org header.s=k20201202 header.b=hlX9DSde; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238475AbjFLUvY (ORCPT + 99 others); Mon, 12 Jun 2023 16:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238095AbjFLUtC (ORCPT ); Mon, 12 Jun 2023 16:49:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DCB6296B for ; Mon, 12 Jun 2023 13:46:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EEDDF62F26 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFB9DC43444; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=GOuO4QtR996HCmcdYQAWMIyqhycVTQWVHdyq4/4h32g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hlX9DSdeVteob3wFd4346DXdfp9KfFrfNJiGAadHUIRiM6b+gRTHNEz55OCXoCxeu wcmoVXHUN/Rm6bbMMhM6nv2BgUopEg1fxrK0EwG6Qfsv524xW7vZR32zJvrsb8zDX1 S8Kct9/+0fmKNRLv2YDiwFcTcb9SCf/7yo6HKe8os/YoFWVDuwi6vTCTfRAK7ToMxu gzxchzk2GJFjeehNtu691BdXiQTsE+u4Y5NRS2nrvXgt+j7MqGtNdR/YHsRVlZiF3p thnz5Qdwc0gC3C1nxga7E+bdlSOGiRDL+LpnoNNv6T+9VKLsj3vIysP4BCnl7B97d2 T/jxKSuR7M0Eg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DF9B1CE3A6A; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Palmer Dabbelt , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 24/53] tools/nolibc: riscv: add stackprotector support Date: Mon, 12 Jun 2023 13:44:45 -0700 Message-Id: <20230612204514.292087-24-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Thomas Weißschuh Signed-off-by: Thomas Weißschuh Acked-by: Palmer Dabbelt Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- 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 992a1739dd9c..d0439249c9c9 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -177,14 +177,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 REG_L" 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 6d660d922240..bd41102ea299 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -85,6 +85,7 @@ CFLAGS_STKP_x86 = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm64 = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_mips = $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_riscv = $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_loongarch = $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 = -m64 CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \ -- 2.40.1