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: 56240 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 D7C923858035 for ; Mon, 16 Oct 2023 06:03:10 +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+patchwork=sourceware.org@sourceware.org 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