From patchwork Mon Oct 16 06:02:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 15400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3261125vqb; Sun, 15 Oct 2023 23:03:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsjz7mW4gxx6lTkrGEqVpqupdXV/KWWf5XJINzmxK6E3DM3sA2aL73zvr+Rs3fkX2D3V0m X-Received: by 2002:a05:620a:c0e:b0:770:fc39:25e4 with SMTP id l14-20020a05620a0c0e00b00770fc3925e4mr27805338qki.45.1697436180908; Sun, 15 Oct 2023 23:03:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697436180; cv=pass; d=google.com; s=arc-20160816; b=hp8HImqGNBgBzCQGEtW4ncM+aflu2rJMgKvZvvS1RCey4kv1Mrn4qUGe+AfZ+9hFZo WVz7lpqGfExGE0ErFVpTksA4RZJAaF5MoUkMi/dhAtGVGaw32cdMZXWKa6EB72mfJltO 3xPftNfFGYney1zkq5zkYi9MVecFmGcVdsKyGcxmTNEFJRTsV8B4dqH2JcNANrOXCy4a wvOkj56DOOvqOZNu8leZTVtCb9IMp3P8GzUpVn2seLRiEnrRvs6gWkJGAf7aX9HPRoLD laPu9SXG1Z3FZo095O0PotaIEL+nfKeh95JibXKT3SNBTG27gZfVMIwtmtvUqnFxCmuW N+nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=oi1n4uLJeubQnyHpOdHEaEangXHqPTsHbaTNT+Jy6ZI=; fh=Q+ZPQdyJDzJx4BfovHNTR1lP4msTSfN6TDra8V1lyf8=; b=LUhlM4GDo2cI2E+abEaf6j79ZW8tBGzmMtRs2X8wjJ4I2ffBt6ZvDW5smOvRobYNQN zZp2WhCFwqLP8ELPanciE7DUvylO5kJo+bisoO35n2HcFTOtmPzyGVL96GdaqWR8FQaD voj0BtuhJTZtAgx4ri6Yw3rzm9SmYMSlTPjA50B/U64THSBFM3HoIpSAy37xEqRHd2q1 Fxyn5Hu+jjun+anONBdtYXDaR1HILUVJGQl9yi5oOZOibDPhsUAKcdAjBSIgziuJ36FC 9yKyoDtvS8E6mQf1VB4zt+QLLyGZq0DyiUooqzYz3wJw0A3BKu9c8VXxy3fhT/+mr8v4 Z3XQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@irq.a4lg.com header.s=2017s01 header.b=FKicVunX; arc=pass (i=1); 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=irq.a4lg.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m11-20020a05620a24cb00b0076edc6ca0afsi4935310qkn.172.2023.10.15.23.03.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:03:00 -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=@irq.a4lg.com header.s=2017s01 header.b=FKicVunX; arc=pass (i=1); 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=irq.a4lg.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AA3A4385841D for ; Mon, 16 Oct 2023 06:03:00 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 483A63858D37 for ; Mon, 16 Oct 2023 06:02:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 483A63858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 483A63858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=153.120.152.154 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697436176; cv=none; b=iVBO6lABg4BDI1GnxunjUtlrh9Yt4/BHoHWbH5CWLORMx4UiXjfdiTbKOIN8OdLhjQr5GGAjrJw5f7MOuhwAKK2WHfK0tvoFYIFkrbGunDARHHU80bM7TlSy1RlkKkmEp8Jaz0XJnL57BKLGEsWceYXp1Cu9S9eCGKr2m/UfgaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697436176; c=relaxed/simple; bh=r7zVReQVV2egPaiREPkRv295NCI48n9N/7QcSdLt3nk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=uKo9WVNSpbUVqNpSB86il3BabOETpAbnaM4uKyTtW32LTqiRMzub+YnDzozybIX6NptzHWPsgpCge5lCUXCJ1ieE2ChDQZt+ZPfX0ooyz/4Bm3dJhb5rNJfzLpZivFQieI8h7telQBtLm+PD7Zu2WMcx8mNmNvRiv41peCZXSsU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 1DEFA300089; Mon, 16 Oct 2023 06:02:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1697436171; bh=oi1n4uLJeubQnyHpOdHEaEangXHqPTsHbaTNT+Jy6ZI=; h=From:To:Cc:Subject:Date:Message-ID:Mime-Version:Content-Type: Content-Transfer-Encoding; b=FKicVunXP8A+vcW9t/ROUIUtTVQkCBTw0tjk4weKJ2z7Cr6PfatsNztd1CIYN6Umc WFJF1xchpV04UApf5GJQqjBfQpI3Pbn7fY3prgwjI5o9yuRXibSyDiTczCjxG7T4vm 04BhZDbE6Tju+qjhuxQHiqpclFRkmp8AVFusnXK0= From: Tsukasa OI To: Tsukasa OI , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu , Kito Cheng Cc: binutils@sourceware.org Subject: [PATCH 0/2] RISC-V: Strict relocation handling Date: Mon, 16 Oct 2023 06:02:35 +0000 Message-ID: Mime-Version: 1.0 X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KAM_MANYTO, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779890840815358358 X-GMAIL-MSGID: 1779890840815358358 Hi, [Background] RISC-V BFD ELF handler has many relocation types but some of them are internal use only (must not be placed on either object file or resulting executable/shared library file). [Description: PATCH 2/2] And after RISC-V psABI version 1.0 is ratified, this ABI specification is getting improved and enhanced. Tatsuyuki Ishi enhanced the TLS descriptor model with four new relocation types [1]. Luís Marques added (non-internal) GP-relative relocations (with three new relocation types) [2]. [1] [2] Of which, numbers 47-49 conflict with Binutils' internal relocation types. Note that, though GP-relative relocations are similar to GNU Binutils' internal ones, psABI ones (proposed by Luís) does not allow changing rd (destination register) to gp/zero, requiring separate relocation types. Also, GNU Binutils' ones only accept one instruction relocations. That's exactly why both psABI's TPREL_LO12_[IS] (corresponding GNU Binutils' R_RISCV_TPREL_LO12_[IS]) and GNU Binutils' internal R_RISCV_TPREL_[IS] are still there. We are not sure whether those new relocation types will get ratified but at least should be aware of them. | N | psABI type (draft) | Binutils type | | -- | ------------------- | --------------- | | 47 | GPREL_LO12_I | R_RISCV_GPREL_I | | 48 | GPREL_LO12_S | R_RISCV_GPREL_S | | 49 | GPREL_HI20 | R_RISCV_TPREL_I | | 50 | (reserved) | R_RISCV_TPREL_S | So, we should move those internal only relocation types. That's the intent of PATCH 2/2 and moves internal ones them to unused/reserved spaces (41-42 [GPREL] and 66-67 [TPREL]). [Description: PATCH 1/2] Also in the first place, this kind of change and the current design reusing the same relocation type space both for external ones and internal only ones poses an issue: a new relocation type may be a severe problem on the future. We haven't rejected such internal use only relocation types such as R_RISCV_GPREL_I and R_RISCV_RVC_LUI. The effect if internal only type is accidentally fed into the older linker is pretty much unpredictable. Before an accident happens, we should start rejecting unknown relocation types, at least on the linker. PATCH 1/2 allows only known relocation types and explicitly rejects internal only relocation types (when the object file is fed to the linker, the check only happens before linker relaxation occurs, allowing linker relaxation to use internal only relocation types). By adding separate checks, this patch also rejects unknown relocation types on other tools such as objdump and objcopy. Changes on the tools (summary): They *did* reject unknown *big* relocation types (e.g. relocation type 191 == 0xBF) but not *small* relocation types and internal use only ones. PATCH 1/2 makes them to reject those small/internal relocations. Sincerely, Tsukasa Tsukasa OI (2): RISC-V: Reject invalid relocation types RISC-V: Renumber internal-only [GT]PREL_[IS] reloc bfd/elfnn-riscv.c | 77 +++++++++++++++++++++++- bfd/elfxx-riscv.c | 140 +++++++++++++++++++++++++------------------- include/elf/riscv.h | 15 +++-- 3 files changed, 166 insertions(+), 66 deletions(-) base-commit: 6674b23fe6409e08de9c36f640bd58127eff9dda