From patchwork Wed Nov 8 18:14:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 163128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp1098970vqo; Wed, 8 Nov 2023 10:16:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjUaQTB+XPk7LNCEZxs5lujaR90U1DIrLWboQtXmjKDWvtDNtR7BDAygoWpRX9BURS5g3t X-Received: by 2002:a17:903:1ca:b0:1c9:fdf0:f69 with SMTP id e10-20020a17090301ca00b001c9fdf00f69mr3040330plh.63.1699467387649; Wed, 08 Nov 2023 10:16:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699467387; cv=none; d=google.com; s=arc-20160816; b=MnKQGOdTbJ07IXq8VolhDaiA0DjTOO9ISuAsRej2sjKEwe6PyFSGEA3M0F4GJFehwO tNuCBmUKl/myG94zHzGWPHdC5L34yW87tqOMQaA0PmS0ygi4XEqxDs8bl0Ww6jZPdDob mTD4yFKZXQcQ/f27VyJnLosXwiKI9020l0npCrl1OPoNUVhyRasLYwSPlpK4Ll5Dlrdk /UUQm4L5rItgwkb6cAsDw8heiLW/jKnFEdP0cIDqIf+gAxhoFbiUg0lIT89DXXeC9iyf n0RhaNAN/9at+U9raDwisA+GFCLFXib9GuCNGc+GLtu1SllPqS1vsdrb0sctmT/De5LL pFGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=/IPHaEP+LMC4vMSFU6VXmnYk5+D23vtBI06reGorOKE=; fh=Qbk0RS4bf6GjbhGkpgFoVgYg5V+1DfWcZ6CAErfO2MQ=; b=R3mM/s8R5RV52hj2XDAClomNaWPOhghIOzvr3Zf/1gx3zVCMgmJHeeYYl6hz87cjcL kWqjZBgGqbb1oj6bGAzj7KfKbxdoGuq2lxS91l7yk7n9i8nggJ8wzLp8cKBmkDCVP48s kfHKc3RHAgD3qRJvk2lzWU2PfqH5UB07PoHhaemmMwumDqzfRNNqYy5WOpXpK19MQLXd DBEGG12JyvxrFX1rvBWJRRoQIaSHAQQSUN3k/40oaC0aBYGDGFNQeYoqE9HMQXMOzRTA SMHWJrPjnde+vOwjWB9tjxCvuqiIfhg5pkPSZug+E/zHg9Wu8PTT2bba6//G41ldE+6C 58hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=stTvblAt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id o18-20020a170902d4d200b001ca3cd7ead6si2983637plg.452.2023.11.08.10.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 10:16:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=stTvblAt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 542678060CBD; Wed, 8 Nov 2023 10:15:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231923AbjKHSPA (ORCPT + 32 others); Wed, 8 Nov 2023 13:15:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbjKHSO7 (ORCPT ); Wed, 8 Nov 2023 13:14:59 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23C5B1FEE; Wed, 8 Nov 2023 10:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1699467295; bh=BwZjAK9qEtDtquMpNAzCqMoIeUdxSwsVoif00t8/fG0=; h=From:Date:Subject:To:Cc:From; b=stTvblAtssYrgSehAYvzjjGwocbrT13FfDCn2Z6Ycic6PkW++ZXYbikwU67CxzJ9C NFHm2gE0dUOIR+3a9O+hKImJBKcbPvfWW63uAvNpaDGDzBzAdlmcrFkOx4vHy7VtXT Jy6uyMZ1CP0c2y3QAFRROs3rDCjP8hAtNEvq7cQM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 08 Nov 2023 19:14:43 +0100 Subject: [PATCH v2] tools/nolibc: mips: add support for PIC MIME-Version: 1.0 Message-Id: <20231108-nolibc-pic-v2-1-4fb0d6284757@weissschuh.net> X-B4-Tracking: v=1; b=H4sIABLQS2UC/03Myw6CMBCF4Vchs7ZmelGEle9hWEAZ7CSmkA6ih vDuVlYu/5OcbwWhxCRQFyskWlh4jDnMoQAf2ngnxX1uMFiWWGmn4vjgzquJvbKIzg5Dhw4t5MO UaOD3jt2a3IFlHtNntxf9WzNjrNZ4+WcWrbSqurJ1pupP7bm/vohFxIdnOEaaodm27QvZSD9Jq QAAAA== To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1699467293; l=2546; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=BwZjAK9qEtDtquMpNAzCqMoIeUdxSwsVoif00t8/fG0=; b=/2x+alqOzCUKEQdtzFYWNM/8F+3apyB7ma/lHuuYrz7usvWzgNEaTpwBX0e9Y2HEyWJnRfgO5 qxmOJz5CbrJCWz9TTeHE0EjVYklXN9KaqfMUFLQkGoYnl9BBNxSHBfW X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 08 Nov 2023 10:15:40 -0800 (PST) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782019842015613437 X-GMAIL-MSGID: 1782020715443847783 MIPS requires some extra instructions to set up the $gp register for the with a pointer to the global data area. This isn't needed for non-PIC builds, but this patch enables the code unconditionally to prevent bitrot. Also enable PIC in one of the test configurations for ongoing validation. Signed-off-by: Thomas Weißschuh --- Changes in v2: - Preserver 8-byte alignment of stack pointer - Link to v1: https://lore.kernel.org/r/20231108-nolibc-pic-v1-1-9b7a429d5a6d@weissschuh.net --- tools/include/nolibc/arch-mips.h | 7 ++++++- tools/testing/selftests/nolibc/Makefile | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) --- base-commit: ba335752620565c25c3028fff9496bb8ef373602 change-id: 20770914-nolibc-pic-30043ffb0403 Best regards, diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 3a2c76716b83..62cc50ef3288 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -184,8 +184,13 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_ __asm__ volatile ( ".set push\n" ".set noreorder\n" - ".option pic0\n" + "bal 1f\n" /* prime $ra for .cpload */ + "nop\n" + "1:\n" + ".cpload $ra\n" "move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */ + "addiu $sp, $sp, -4\n" /* space for .cprestore to store $gp */ + ".cprestore 0\n" "li $t0, -8\n" "and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */ "addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 508435b8ac2a..484bb02d8e6c 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -144,7 +144,7 @@ CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2) CFLAGS_s390 = -m64 -CFLAGS_mips32le = -EL -mabi=32 +CFLAGS_mips32le = -EL -mabi=32 -fPIC CFLAGS_mips32be = -EB -mabi=32 CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \