From patchwork Mon Nov 6 09:49:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nelson Chu X-Patchwork-Id: 161913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2545356vqu; Mon, 6 Nov 2023 01:49:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGO9rBKS/4IzgWD0dnVe+Rvp3CNkJxI66rOLrqezInfbzD/Zt/UsJfkkwS2MLpQkAEMfAWq X-Received: by 2002:ac8:4e4d:0:b0:41e:1ead:aa35 with SMTP id e13-20020ac84e4d000000b0041e1eadaa35mr39063720qtw.31.1699264188535; Mon, 06 Nov 2023 01:49:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699264188; cv=pass; d=google.com; s=arc-20160816; b=ildE1CYVxRuNOH5fczd3ZkM3r6fF1BFtdEqdCu3f3CafAZCVQ5of3LqoFkT3G6f07b hy2fYGnFYQF2Z38eZ7jaUAAqJgFEfP1bxsL9TUhhUg4r0UbGzjBVfBQojEMJKu0AoSmX O0/m7E11Lr1TSTtFfgESZZI6JdcF2wpTTiJa3WQrT+Ir7qzTBi6VQyScJ9zMgmCWZ8C+ 6VPf8D1d6TJjB73ydG5XGOgzLqYX6Co0xWIQeGByxFRCK5tpBGr0xPk+1bPN1R0ja4cJ +R+2lSHL37AbF6xJkEVO0JzOP1BIm/9W0diKvkNCWT6i1FF41wkmd/PkOC6AN/BdiDnR bUNg== 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:arc-filter :dmarc-filter:delivered-to; bh=mRcV7+A/Gy20vFAMtrKzCrDgcHgP7Ycy6iKOGNTGNPY=; fh=A0tLN7XfZratXDKXa0Mdmx16tZuMO5wKHXvESmMplWQ=; b=xfjcey/nRdkz7lO1PNMWe/zn2IxuUNS03nWOfYHSTWFrAae5nuqUxcYD8GIbfZdMJW UIahUSHyoxbjxsD5jaPyTqWbTiJai8qMZ9j4EBpgmWHsstBJHX7bmJ7YIDCVhLqA85hW u9zdzw+E+tsN/5p1Ysv6hDKyx0vy3ZHDfRUT/6cDhplfyJijoG8qsPwA8jWq7pxCKaxI r02lxEW5E+mljpAenH8b7bIW29bXQMMqtAn33IdqBjk59MFEpf+7DOBCan27M0gN05Hs blQI7KE0RRSAQK+inNp6I3Rz6bzaDEDUDn/btCf+yo53yrav/iNDonRPhECWy7MaZETv 4vog== ARC-Authentication-Results: i=2; mx.google.com; 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" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u3-20020ac858c3000000b0041964841177si5192505qta.406.2023.11.06.01.49.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 01:49:48 -0800 (PST) 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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EB13385841A for ; Mon, 6 Nov 2023 09:49:48 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from NelsondeMBP.localdomain (36-230-182-87.dynamic-ip.hinet.net [36.230.182.87]) by sourceware.org (Postfix) with ESMTP id 9C2B03858D28 for ; Mon, 6 Nov 2023 09:49:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C2B03858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=NelsondeMBP.localdomain ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C2B03858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=36.230.182.87 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699264181; cv=none; b=KcQUBZJEJYsX+PY3IYAn/tUFce5uuZQNHbJCBQF2Ah8V4mxHe2YmsPs+CjMPGBtAjxQmgdXRrXkz3veJYX/IR92OdkAXO0IQ+7WxHCt54gDxmyLku6xPGUPdLu2k/1mOmaQIdQaWo5ENxgD16zH5iRZCKPsjAGhQTnsQ+UKrNLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699264181; c=relaxed/simple; bh=OwAO5f5Zehstm5GiBJ6Xfp/RjFVxog/tNjQk/cXHy+s=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=I1R6yo0zIst3hKd7dx4emhR/ACO4UjZ3ywPckNjc5JIP6k7VjEVCEf367et7vm6jS0O5dF9sJ9baSY3qisiLD8kRjVjzTky7BszpffBf6rEEYF6vIfoEjls82sc4iopUQFmhTSSdwQFi3j7HApo7nf7aT3PcCf50GOcOnn5UwwE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by NelsondeMBP.localdomain (Postfix, from userid 501) id 1C7A71365CEF; Mon, 6 Nov 2023 17:49:36 +0800 (CST) From: Nelson Chu To: binutils@sourceware.org Cc: ishitatsuyuki@gmail.com, Nelson Chu , Tsukasa OI Subject: [committed] RISC-V: Moved out linker internal relocations after R_RISCV_max. Date: Mon, 6 Nov 2023 17:49:34 +0800 Message-Id: <20231106094935.97856-1-nelson@rivosinc.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) MIME-Version: 1.0 X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, NO_DNS_FOR_FROM, RCVD_IN_PBL, RCVD_IN_SORBS_DUL, RDNS_DYNAMIC, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781807646064406006 X-GMAIL-MSGID: 1781807646064406006 Just the lightest modifications about this, without any further checks and considering --emit-relocs. We will need to improve it in the future, but first do this to avoid conflicts between linker internal relocations and the new definition of psabi. For example, TLSDESC relocs. Passed riscv-gnu-toolchain regressions, so should be safe enough to commit. Co-authored-by: Tsukasa OI bfd/ * reloc.c: Removed linker internal relocations. * bfd-in2.h: Regenerated. * libbfd.h: Regenerated. * elfnn-riscv.c: Defined R_RISCV_DELETE in include/elf/riscv.h. * elfxx-riscv.c (howto_table, howto_table_internal): Moved linker internal relocations from howto_table into howto_table_internal. (riscv_reloc_map): Removed linker internal relocations mapping. (riscv_elf_rtype_to_howto): Return howto of linker internal relocations from howto_table_internal. include/ * elf/riscv.h: Defined linker internal relocations after R_RISCV_max. --- bfd/bfd-in2.h | 5 -- bfd/elfnn-riscv.c | 3 - bfd/elfxx-riscv.c | 178 +++++++++++++++++++++++--------------------- bfd/libbfd.h | 5 -- bfd/reloc.c | 10 --- include/elf/riscv.h | 8 ++ 6 files changed, 101 insertions(+), 108 deletions(-) diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index e26bc40a9e1..96eef92fdc7 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -5399,11 +5399,6 @@ enum bfd_reloc_code_real BFD_RELOC_RISCV_ALIGN, BFD_RELOC_RISCV_RVC_BRANCH, BFD_RELOC_RISCV_RVC_JUMP, - BFD_RELOC_RISCV_RVC_LUI, - BFD_RELOC_RISCV_GPREL_I, - BFD_RELOC_RISCV_GPREL_S, - BFD_RELOC_RISCV_TPREL_I, - BFD_RELOC_RISCV_TPREL_S, BFD_RELOC_RISCV_RELAX, BFD_RELOC_RISCV_CFA, BFD_RELOC_RISCV_SUB6, diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 00e5c69dbec..5c4bf4bc3cb 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -130,9 +130,6 @@ } \ while (0) -/* Internal relocations used exclusively by the relaxation pass. */ -#define R_RISCV_DELETE (R_RISCV_max + 1) - #define ARCH_SIZE NN #define MINUS_ONE ((bfd_vma)0 - 1) diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index c070394a366..937ab7a6deb 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -218,7 +218,6 @@ static reloc_howto_type howto_table[] = MINUS_ONE, /* dst_mask */ false), /* pcrel_offset */ - /* Reserved for future relocs that the dynamic linker must understand. */ EMPTY_HOWTO (12), EMPTY_HOWTO (13), EMPTY_HOWTO (14), @@ -601,9 +600,8 @@ static reloc_howto_type howto_table[] = MINUS_ONE, /* dst_mask */ false), /* pcrel_offset */ - /* 41 and 42 are reserved. */ - EMPTY_HOWTO (0), - EMPTY_HOWTO (0), + EMPTY_HOWTO (41), + EMPTY_HOWTO (42), /* Indicates an alignment statement. The addend field encodes how many bytes of NOPs follow the statement. The desired alignment is the @@ -652,80 +650,11 @@ static reloc_howto_type howto_table[] = ENCODE_CJTYPE_IMM (-1U), /* dst_mask */ true), /* pcrel_offset */ - /* High 6 bits of 18-bit absolute address. */ - HOWTO (R_RISCV_RVC_LUI, /* type */ - 0, /* rightshift */ - 2, /* size */ - 16, /* bitsize */ - false, /* pc_relative */ - 0, /* bitpos */ - complain_overflow_dont, /* complain_on_overflow */ - bfd_elf_generic_reloc, /* special_function */ - "R_RISCV_RVC_LUI", /* name */ - false, /* partial_inplace */ - 0, /* src_mask */ - ENCODE_CITYPE_IMM (-1U), /* dst_mask */ - false), /* pcrel_offset */ - - /* GP-relative load. */ - HOWTO (R_RISCV_GPREL_I, /* type */ - 0, /* rightshift */ - 4, /* size */ - 32, /* bitsize */ - false, /* pc_relative */ - 0, /* bitpos */ - complain_overflow_dont, /* complain_on_overflow */ - bfd_elf_generic_reloc, /* special_function */ - "R_RISCV_GPREL_I", /* name */ - false, /* partial_inplace */ - 0, /* src_mask */ - ENCODE_ITYPE_IMM (-1U), /* dst_mask */ - false), /* pcrel_offset */ - - /* GP-relative store. */ - HOWTO (R_RISCV_GPREL_S, /* type */ - 0, /* rightshift */ - 4, /* size */ - 32, /* bitsize */ - false, /* pc_relative */ - 0, /* bitpos */ - complain_overflow_dont, /* complain_on_overflow */ - bfd_elf_generic_reloc, /* special_function */ - "R_RISCV_GPREL_S", /* name */ - false, /* partial_inplace */ - 0, /* src_mask */ - ENCODE_STYPE_IMM (-1U), /* dst_mask */ - false), /* pcrel_offset */ - - /* TP-relative TLS LE load. */ - HOWTO (R_RISCV_TPREL_I, /* type */ - 0, /* rightshift */ - 4, /* size */ - 32, /* bitsize */ - false, /* pc_relative */ - 0, /* bitpos */ - complain_overflow_signed, /* complain_on_overflow */ - bfd_elf_generic_reloc, /* special_function */ - "R_RISCV_TPREL_I", /* name */ - false, /* partial_inplace */ - 0, /* src_mask */ - ENCODE_ITYPE_IMM (-1U), /* dst_mask */ - false), /* pcrel_offset */ - - /* TP-relative TLS LE store. */ - HOWTO (R_RISCV_TPREL_S, /* type */ - 0, /* rightshift */ - 4, /* size */ - 32, /* bitsize */ - false, /* pc_relative */ - 0, /* bitpos */ - complain_overflow_signed, /* complain_on_overflow */ - bfd_elf_generic_reloc, /* special_function */ - "R_RISCV_TPREL_S", /* name */ - false, /* partial_inplace */ - 0, /* src_mask */ - ENCODE_STYPE_IMM (-1U), /* dst_mask */ - false), /* pcrel_offset */ + EMPTY_HOWTO (46), + EMPTY_HOWTO (47), + EMPTY_HOWTO (48), + EMPTY_HOWTO (49), + EMPTY_HOWTO (50), /* The paired relocation may be relaxed. */ HOWTO (R_RISCV_RELAX, /* type */ @@ -881,6 +810,87 @@ static reloc_howto_type howto_table[] = false), /* pcrel_offset */ }; +static reloc_howto_type howto_table_internal[] = +{ + /* R_RISCV_DELETE. */ + EMPTY_HOWTO (0), + + /* High 6 bits of 18-bit absolute address. */ + HOWTO (R_RISCV_RVC_LUI, /* type */ + 0, /* rightshift */ + 2, /* size */ + 16, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_RVC_LUI", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_CITYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + + /* GP-relative load. */ + HOWTO (R_RISCV_GPREL_I, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_GPREL_I", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_ITYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + + /* GP-relative store. */ + HOWTO (R_RISCV_GPREL_S, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_GPREL_S", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_STYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + + /* TP-relative TLS LE load. */ + HOWTO (R_RISCV_TPREL_I, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_signed, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TPREL_I", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_ITYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + + /* TP-relative TLS LE store. */ + HOWTO (R_RISCV_TPREL_S, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_signed, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TPREL_S", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_STYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ +}; + /* A mapping from BFD reloc types to RISC-V ELF reloc types. */ struct elf_reloc_map { @@ -928,11 +938,6 @@ static const struct elf_reloc_map riscv_reloc_map[] = { BFD_RELOC_RISCV_ALIGN, R_RISCV_ALIGN }, { BFD_RELOC_RISCV_RVC_BRANCH, R_RISCV_RVC_BRANCH }, { BFD_RELOC_RISCV_RVC_JUMP, R_RISCV_RVC_JUMP }, - { BFD_RELOC_RISCV_RVC_LUI, R_RISCV_RVC_LUI }, - { BFD_RELOC_RISCV_GPREL_I, R_RISCV_GPREL_I }, - { BFD_RELOC_RISCV_GPREL_S, R_RISCV_GPREL_S }, - { BFD_RELOC_RISCV_TPREL_I, R_RISCV_TPREL_I }, - { BFD_RELOC_RISCV_TPREL_S, R_RISCV_TPREL_S }, { BFD_RELOC_RISCV_RELAX, R_RISCV_RELAX }, { BFD_RELOC_RISCV_SUB6, R_RISCV_SUB6 }, { BFD_RELOC_RISCV_SET6, R_RISCV_SET6 }, @@ -975,14 +980,17 @@ riscv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) reloc_howto_type * riscv_elf_rtype_to_howto (bfd *abfd, unsigned int r_type) { - if (r_type >= ARRAY_SIZE (howto_table)) + if (r_type < ARRAY_SIZE (howto_table)) + return &howto_table[r_type]; + else if (r_type < R_RISCV_max + ARRAY_SIZE (howto_table_internal)) + return &howto_table_internal[r_type - R_RISCV_max]; + else { (*_bfd_error_handler) (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); return NULL; } - return &howto_table[r_type]; } /* Special_function of RISCV_ADD and RISCV_SUB relocations. */ diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 1ce6bc12b7e..fce0680f3db 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -2400,11 +2400,6 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_RISCV_ALIGN", "BFD_RELOC_RISCV_RVC_BRANCH", "BFD_RELOC_RISCV_RVC_JUMP", - "BFD_RELOC_RISCV_RVC_LUI", - "BFD_RELOC_RISCV_GPREL_I", - "BFD_RELOC_RISCV_GPREL_S", - "BFD_RELOC_RISCV_TPREL_I", - "BFD_RELOC_RISCV_TPREL_S", "BFD_RELOC_RISCV_RELAX", "BFD_RELOC_RISCV_CFA", "BFD_RELOC_RISCV_SUB6", diff --git a/bfd/reloc.c b/bfd/reloc.c index 6e9377c31ce..93ebad879e0 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -4990,16 +4990,6 @@ ENUMX BFD_RELOC_RISCV_RVC_BRANCH ENUMX BFD_RELOC_RISCV_RVC_JUMP -ENUMX - BFD_RELOC_RISCV_RVC_LUI -ENUMX - BFD_RELOC_RISCV_GPREL_I -ENUMX - BFD_RELOC_RISCV_GPREL_S -ENUMX - BFD_RELOC_RISCV_TPREL_I -ENUMX - BFD_RELOC_RISCV_TPREL_S ENUMX BFD_RELOC_RISCV_RELAX ENUMX diff --git a/include/elf/riscv.h b/include/elf/riscv.h index 0aa8b3359c4..56d419c665b 100644 --- a/include/elf/riscv.h +++ b/include/elf/riscv.h @@ -92,6 +92,14 @@ START_RELOC_NUMBERS (elf_riscv_reloc_type) RELOC_NUMBER (R_RISCV_SUB_ULEB128, 61) END_RELOC_NUMBERS (R_RISCV_max) +/* Internal relocations used exclusively by the relaxation pass. */ +#define R_RISCV_DELETE (R_RISCV_max) +#define R_RISCV_RVC_LUI (R_RISCV_max + 1) +#define R_RISCV_GPREL_I (R_RISCV_max + 2) +#define R_RISCV_GPREL_S (R_RISCV_max + 3) +#define R_RISCV_TPREL_I (R_RISCV_max + 4) +#define R_RISCV_TPREL_S (R_RISCV_max + 5) + /* Processor specific flags for the ELF header e_flags field. */ /* File may contain compressed instructions. */