From 0c4b8ed69c5713e567b6c1d866f6d8cdb9de11f7 Mon Sep 17 00:00:00 2001 From: Nelson Chu Date: Mon, 6 Nov 2023 13:28:51 +0800 Subject: [PATCH] RISC-V: Moved out linker internal relocations after R_RISCV_max. 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. */ -- 2.30.2