From patchwork Mon Sep 25 08:19:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 144268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1054060vqu; Mon, 25 Sep 2023 01:20:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHD21GgMn3z74ayWQPJmLXDqna8SMGHOeZMk6a4uG1bJRIQ/e3v5wkWgWkzIod/cHKncJat X-Received: by 2002:a50:ee01:0:b0:530:c386:b277 with SMTP id g1-20020a50ee01000000b00530c386b277mr5291043eds.7.1695630009099; Mon, 25 Sep 2023 01:20:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630009; cv=none; d=google.com; s=arc-20160816; b=i87H2uICMWW/hr0SKeLtks9c9GUGOEEvStoBhAiSEYC9/tgbU+6h/fjH1hvQiZgZoE vLD5PL34hPdYuIAjGSYransUiTpi44D0ct/K3eaLBWGmeKRCKVpkt2Xyopl22b3zdReW afBhjkqoJB6wNVWSm87lrnGLW4820TuZIGOcp4adj0iaOcuOJ0BJiI9fOf04GD2PRXX9 bEGLmtVnUFYBsrr/n9K++oK+pKI+2vdorRWOOIMl9IM9lEhhIhdA0vlo6FJKir6WKcY6 O5q7L4x2Le+hyBLoh45dGTYhK+bLWqeePY6XgDh296kvTRWe03UmqS4fLS4AYa3zRwYM 1k2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:message-id:date:cc:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=/Ed9Upq7MzF8Z2ZxDbZpy/nkMyTxd+xvrYV7hIQL2P8=; fh=mA+7sWD1y08RkLY7mUQWvUpm7mSUMiUPd3vaXsYEV1E=; b=OUsgY9awTyb7Dn6RiwQ0qSiKmXKU6+1vDkjm1CJqfYz1cYLii6fyPZ3dq+k4HQR4UV GtX1dZHImedROQ/YerjJROVW/+86K0ZDrSf73SLQOFM/2gIDbDDxENd8/kZz30bpMjFy Cm0Vy+0vfS4ZK5+aiTghHZJm61mHB3uAh+4exXa3qOUJOs76EM60dnZDN9L5qOvohcF8 NR2REt7EwfLwitmJYljID81L/mMEguKZgx6oUfoJ9w5XW+5l1QJWgVXCswsQ9GANQU0r dJaYBcPqSNNwO2B62CYtXL0ZVnpMbxZU/M499MWp/J3JdNvd5wsZAGO0qCJ1Ksq6NQl0 ScvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=KEcaQGTd; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z4-20020aa7d404000000b005333aafa3f5si7641216edq.244.2023.09.25.01.20.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:20:09 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=KEcaQGTd; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03ED43857717 for ; Mon, 25 Sep 2023 08:20:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03ED43857717 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695630008; bh=/Ed9Upq7MzF8Z2ZxDbZpy/nkMyTxd+xvrYV7hIQL2P8=; h=To:Subject:CC:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=KEcaQGTd7FwcUPC8vHjFXeEsBrrotvw7RzYqqANmsNyOEVXX2VVLHlb3Q3euUZBDY RmqTzLU5ucF6/34MfeVlVz+Lsq4u0Yrq3/8wtNMnOFhOk4FcY9V7/Ca5RyR8Bp2xej nkW8p2M+O4iLvbp8vhoTbnJ9yvpboTUtINIvmu9E= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id AA9863858CDA for ; Mon, 25 Sep 2023 08:19:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA9863858CDA Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id DE0591F74D; Mon, 25 Sep 2023 08:19:57 +0000 (UTC) Received: from hawking.nue2.suse.org (unknown [10.168.4.11]) by relay2.suse.de (Postfix) with ESMTP id BC8AE2C142; Mon, 25 Sep 2023 08:19:57 +0000 (UTC) Received: by hawking.nue2.suse.org (Postfix, from userid 17005) id C3C744A03CD; Mon, 25 Sep 2023 10:19:57 +0200 (CEST) To: binutils@sourceware.org Subject: [PATCH] RISC-V: Protect .got with relro CC: nelson@rivosinc.com, palmer@dabbelt.com X-Yow: With YOU, I can be MYSELF.. We don't NEED Dan Rather.. Date: Mon, 25 Sep 2023 10:19:57 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andreas Schwab via Binutils From: Andreas Schwab Reply-To: Andreas Schwab Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996932487566303 X-GMAIL-MSGID: 1777996932487566303 Move .got before .data so that it can be protected with -zrelro. Also separate .got.plt from .got if -znow is not in effect; the first two words of .got.plt are placed within the relro region. ld: PR ld/30877 * emulparams/elf32lriscv-defs.sh (DATA_GOT, SEPARATE_GOTPLT): Define. * emulparams/elf64lriscv-defs.sh (SEPARATE_GOTPLT): Define. Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt --- ld/emulparams/elf32lriscv-defs.sh | 4 ++++ ld/emulparams/elf64lriscv-defs.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/ld/emulparams/elf32lriscv-defs.sh b/ld/emulparams/elf32lriscv-defs.sh index b823cedacab..016556168c3 100644 --- a/ld/emulparams/elf32lriscv-defs.sh +++ b/ld/emulparams/elf32lriscv-defs.sh @@ -47,3 +47,7 @@ INITIAL_READONLY_SECTIONS="${RELOCATING+${CREATE_SHLIB-${INITIAL_READONLY_SECTIO OTHER_END_SYMBOLS="${CREATE_SHLIB-__BSS_END__ = .; __global_pointer$ = MIN(__SDATA_BEGIN__ + 0x800, MAX(__DATA_BEGIN__ + 0x800, __BSS_END__ - 0x800));}" + +# Put .got before .data +DATA_GOT=" " +SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 8 ? 8 : 0" diff --git a/ld/emulparams/elf64lriscv-defs.sh b/ld/emulparams/elf64lriscv-defs.sh index 84a700a5f58..ca15338428f 100644 --- a/ld/emulparams/elf64lriscv-defs.sh +++ b/ld/emulparams/elf64lriscv-defs.sh @@ -1,2 +1,3 @@ source_sh ${srcdir}/emulparams/elf32lriscv-defs.sh ELFSIZE=64 +SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 16 ? 16 : 0"