From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 96C093858C62 for ; Mon, 25 Sep 2023 09:26:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96C093858C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-690fe10b6a4so5434335b3a.3 for ; Mon, 25 Sep 2023 02:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20230601.gappssmtp.com; s=20230601; t=1695634008; x=1696238808; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=nPdwP1qhfhyLdU2rsDEtz5heK6kIKBAxFbQEcA/8qAU=; b=CNjWP87Q4EWvUElKDuJdDRslCwhtv5Dh9Il5xdzH/vTu4nO7Yvp41eqePkdR2WAaaf j5JceZ+pHLKnpzKxAAxsvz/jd9dcC/bCphDAV63Cr8QZc0nQvF3+Vj68X3aPU/6v33rj wIJDd0CtOxv1S6u6jngSeUkM2X+j3Z9uBjFk3bJbJ+kKXq8mZo8LhLG+IBRyC/d4cBah whZNd+Ggf9lmjhxSq5fJ4/NTsa5h7LqXF8RrLLWbpmxBOl70rUT2UcGdyuRhVGtWa5h0 mxK7N3X4FEU7G6tjmpdj31MnDDujUf8z5KhntCfNSxiGO5JhXDEVALvvU9QuQbaX7rhv NXKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695634008; x=1696238808; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nPdwP1qhfhyLdU2rsDEtz5heK6kIKBAxFbQEcA/8qAU=; b=e12y/DRjuStr6lw78pdUUoaof4h2GruX5o7hzMXhJttHCgN7KCjUbCfL8iz5e/SkN8 bFYyd1+n7coEY2ZjQGWpLBn+iS6VuXDJHp97P6fTzjQdNasrKy3zs27X1IdexdCxbvjY h+7N3LyueXs0IcLOtHN8JFdVQmwoV604ITVnTVfN45ogRFU9cmKLfk2f7Y/DpVl4P1ys gkDC99OvKQAbBjM9564ih+QtrWyu8wh6QyXpoHorTIdTYEErkjUa/hFZJmaRazKmV/22 kFfZwm4tTGUKF34OeH5wW6lTceLtkAykB5xaTAPJAUUAA3XmSra4uL4IBXKuJm/7X7zk d9HA== X-Gm-Message-State: AOJu0YwPLIbI/5N5vSIOIv0xsvgoN8rDhVdI/J0MPtkGiS/4awbVcap1 mCpRD2QyBFEXceOv1jH+jKEuCUnVcrtEsJzowYNMEg== X-Google-Smtp-Source: AGHT+IF8xawqqH1JW0cny/MCl2YFdtwqxqqz9QWuTysoGHRKMtBvhO+F/Wh3WNXcrAGVKPYWnFUtNA== X-Received: by 2002:a05:6a00:847:b0:68f:d320:58bb with SMTP id q7-20020a056a00084700b0068fd32058bbmr8114551pfk.8.1695634008081; Mon, 25 Sep 2023 02:26:48 -0700 (PDT) Received: from localhost ([51.52.155.79]) by smtp.gmail.com with ESMTPSA id fm1-20020a056a002f8100b0068a538cc7adsm7535786pfb.52.2023.09.25.02.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 02:26:47 -0700 (PDT) Date: Mon, 25 Sep 2023 02:26:47 -0700 (PDT) X-Google-Original-Date: Mon, 25 Sep 2023 02:26:43 PDT (-0700) Subject: Re: [PATCH] RISC-V: Protect .got with relro In-Reply-To: CC: binutils@sourceware.org, nelson@rivosinc.com From: Palmer Dabbelt To: schwab@suse.de Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Mon, 25 Sep 2023 01:19:57 PDT (-0700), schwab@suse.de wrote: > 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. > --- > 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" I think we also want something like this diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp index 674e8e9a575..b38e29ed6fb 100644 --- a/ld/testsuite/ld-elf/binutils.exp +++ b/ld/testsuite/ld-elf/binutils.exp @@ -95,7 +95,6 @@ proc binutils_test { prog_name ld_options test {test_name ""} {readelf_options " || [istarget "mips*-*-*"] \ || [istarget "nios2*-*-*"] \ || [istarget "or1k-*-*"] \ - || [istarget "riscv*-*-*"] \ || [istarget "sh*-*-*"] \ || [istarget "x86_64-*-rdos*"])] # Check if GNU_RELRO segment is generated.