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: 76627 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74D2F3858025 for ; Mon, 25 Sep 2023 08:20:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74D2F3858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695630028; 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=JK52y6AO1N3fJREeu3hBekyFBmXvEA4iKNSpiR+33fOWZ4rikbh9Uo2feuYsqhyvJ 4ggK/4hDgu11MPYepj3E3KoM8ZUdSw+5DFMMNF1w4R1ZRAWOXua00KtOzNchFQt4Mg 2beKKTong2PHmyvkGhqgY7J0xdU07+CXkiR90a8k= 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+patchwork=sourceware.org@sourceware.org Sender: "Binutils" 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"