Home | History | Annotate | Line # | Download | only in bfd
elfxx-riscv.c revision 1.1
      1  1.1  christos /* RISC-V-specific support for ELF.
      2  1.1  christos    Copyright (C) 2011-2017 Free Software Foundation, Inc.
      3  1.1  christos 
      4  1.1  christos    Contributed by Andrew Waterman (andrew (at) sifive.com).
      5  1.1  christos    Based on TILE-Gx and MIPS targets.
      6  1.1  christos 
      7  1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      8  1.1  christos 
      9  1.1  christos    This program is free software; you can redistribute it and/or modify
     10  1.1  christos    it under the terms of the GNU General Public License as published by
     11  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12  1.1  christos    (at your option) any later version.
     13  1.1  christos 
     14  1.1  christos    This program is distributed in the hope that it will be useful,
     15  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  1.1  christos    GNU General Public License for more details.
     18  1.1  christos 
     19  1.1  christos    You should have received a copy of the GNU General Public License
     20  1.1  christos    along with this program; see the file COPYING3. If not,
     21  1.1  christos    see <http://www.gnu.org/licenses/>.  */
     22  1.1  christos 
     23  1.1  christos #include "sysdep.h"
     24  1.1  christos #include "bfd.h"
     25  1.1  christos #include "libbfd.h"
     26  1.1  christos #include "elf-bfd.h"
     27  1.1  christos #include "elf/riscv.h"
     28  1.1  christos #include "opcode/riscv.h"
     29  1.1  christos #include "libiberty.h"
     30  1.1  christos #include "elfxx-riscv.h"
     31  1.1  christos #include <stdint.h>
     32  1.1  christos 
     33  1.1  christos #define MINUS_ONE ((bfd_vma)0 - 1)
     34  1.1  christos 
     35  1.1  christos /* The relocation table used for SHT_RELA sections.  */
     36  1.1  christos 
     37  1.1  christos static reloc_howto_type howto_table[] =
     38  1.1  christos {
     39  1.1  christos   /* No relocation.  */
     40  1.1  christos   HOWTO (R_RISCV_NONE,			/* type */
     41  1.1  christos 	 0,				/* rightshift */
     42  1.1  christos 	 3,				/* size */
     43  1.1  christos 	 0,				/* bitsize */
     44  1.1  christos 	 FALSE,				/* pc_relative */
     45  1.1  christos 	 0,				/* bitpos */
     46  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
     47  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
     48  1.1  christos 	 "R_RISCV_NONE",		/* name */
     49  1.1  christos 	 FALSE,				/* partial_inplace */
     50  1.1  christos 	 0,				/* src_mask */
     51  1.1  christos 	 0,				/* dst_mask */
     52  1.1  christos 	 FALSE),			/* pcrel_offset */
     53  1.1  christos 
     54  1.1  christos   /* 32 bit relocation.  */
     55  1.1  christos   HOWTO (R_RISCV_32,			/* type */
     56  1.1  christos 	 0,				/* rightshift */
     57  1.1  christos 	 2,				/* size */
     58  1.1  christos 	 32,				/* bitsize */
     59  1.1  christos 	 FALSE,				/* pc_relative */
     60  1.1  christos 	 0,				/* bitpos */
     61  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
     62  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
     63  1.1  christos 	 "R_RISCV_32",			/* name */
     64  1.1  christos 	 FALSE,				/* partial_inplace */
     65  1.1  christos 	 0,				/* src_mask */
     66  1.1  christos 	 MINUS_ONE,			/* dst_mask */
     67  1.1  christos 	 FALSE),			/* pcrel_offset */
     68  1.1  christos 
     69  1.1  christos   /* 64 bit relocation.  */
     70  1.1  christos   HOWTO (R_RISCV_64,			/* type */
     71  1.1  christos 	 0,				/* rightshift */
     72  1.1  christos 	 4,				/* size */
     73  1.1  christos 	 64,				/* bitsize */
     74  1.1  christos 	 FALSE,				/* pc_relative */
     75  1.1  christos 	 0,				/* bitpos */
     76  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
     77  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
     78  1.1  christos 	 "R_RISCV_64",			/* name */
     79  1.1  christos 	 FALSE,				/* partial_inplace */
     80  1.1  christos 	 0,				/* src_mask */
     81  1.1  christos 	 MINUS_ONE,			/* dst_mask */
     82  1.1  christos 	 FALSE),			/* pcrel_offset */
     83  1.1  christos 
     84  1.1  christos   /* Relocation against a local symbol in a shared object.  */
     85  1.1  christos   HOWTO (R_RISCV_RELATIVE,		/* type */
     86  1.1  christos 	 0,				/* rightshift */
     87  1.1  christos 	 2,				/* size */
     88  1.1  christos 	 32,				/* bitsize */
     89  1.1  christos 	 FALSE,				/* pc_relative */
     90  1.1  christos 	 0,				/* bitpos */
     91  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
     92  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
     93  1.1  christos 	 "R_RISCV_RELATIVE",		/* name */
     94  1.1  christos 	 FALSE,				/* partial_inplace */
     95  1.1  christos 	 0,				/* src_mask */
     96  1.1  christos 	 MINUS_ONE,			/* dst_mask */
     97  1.1  christos 	 FALSE),			/* pcrel_offset */
     98  1.1  christos 
     99  1.1  christos   HOWTO (R_RISCV_COPY,			/* type */
    100  1.1  christos 	 0,				/* rightshift */
    101  1.1  christos 	 0,				/* this one is variable size */
    102  1.1  christos 	 0,				/* bitsize */
    103  1.1  christos 	 FALSE,				/* pc_relative */
    104  1.1  christos 	 0,				/* bitpos */
    105  1.1  christos 	 complain_overflow_bitfield,	/* complain_on_overflow */
    106  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    107  1.1  christos 	 "R_RISCV_COPY",		/* name */
    108  1.1  christos 	 FALSE,				/* partial_inplace */
    109  1.1  christos 	 0,         			/* src_mask */
    110  1.1  christos 	 0,		        	/* dst_mask */
    111  1.1  christos 	 FALSE),			/* pcrel_offset */
    112  1.1  christos 
    113  1.1  christos   HOWTO (R_RISCV_JUMP_SLOT,		/* type */
    114  1.1  christos 	 0,				/* rightshift */
    115  1.1  christos 	 4,				/* size */
    116  1.1  christos 	 64,				/* bitsize */
    117  1.1  christos 	 FALSE,				/* pc_relative */
    118  1.1  christos 	 0,				/* bitpos */
    119  1.1  christos 	 complain_overflow_bitfield,	/* complain_on_overflow */
    120  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    121  1.1  christos 	 "R_RISCV_JUMP_SLOT",		/* name */
    122  1.1  christos 	 FALSE,				/* partial_inplace */
    123  1.1  christos 	 0,         			/* src_mask */
    124  1.1  christos 	 0,		        	/* dst_mask */
    125  1.1  christos 	 FALSE),			/* pcrel_offset */
    126  1.1  christos 
    127  1.1  christos   /* Dynamic TLS relocations.  */
    128  1.1  christos   HOWTO (R_RISCV_TLS_DTPMOD32,		/* type */
    129  1.1  christos 	 0,				/* rightshift */
    130  1.1  christos 	 4,				/* size */
    131  1.1  christos 	 32,				/* bitsize */
    132  1.1  christos 	 FALSE,				/* pc_relative */
    133  1.1  christos 	 0,				/* bitpos */
    134  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    135  1.1  christos 	 bfd_elf_generic_reloc, 	/* special_function */
    136  1.1  christos 	 "R_RISCV_TLS_DTPMOD32",	/* name */
    137  1.1  christos 	 FALSE,				/* partial_inplace */
    138  1.1  christos 	 0,				/* src_mask */
    139  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    140  1.1  christos 	 FALSE),			/* pcrel_offset */
    141  1.1  christos 
    142  1.1  christos   HOWTO (R_RISCV_TLS_DTPMOD64,		/* type */
    143  1.1  christos 	 0,				/* rightshift */
    144  1.1  christos 	 4,				/* size */
    145  1.1  christos 	 64,				/* bitsize */
    146  1.1  christos 	 FALSE,				/* pc_relative */
    147  1.1  christos 	 0,				/* bitpos */
    148  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    149  1.1  christos 	 bfd_elf_generic_reloc, 	/* special_function */
    150  1.1  christos 	 "R_RISCV_TLS_DTPMOD64",	/* name */
    151  1.1  christos 	 FALSE,				/* partial_inplace */
    152  1.1  christos 	 0,				/* src_mask */
    153  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    154  1.1  christos 	 FALSE),			/* pcrel_offset */
    155  1.1  christos 
    156  1.1  christos   HOWTO (R_RISCV_TLS_DTPREL32,		/* type */
    157  1.1  christos 	 0,				/* rightshift */
    158  1.1  christos 	 4,				/* size */
    159  1.1  christos 	 32,				/* bitsize */
    160  1.1  christos 	 FALSE,				/* pc_relative */
    161  1.1  christos 	 0,				/* bitpos */
    162  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    163  1.1  christos 	 bfd_elf_generic_reloc, 	/* special_function */
    164  1.1  christos 	 "R_RISCV_TLS_DTPREL32",	/* name */
    165  1.1  christos 	 TRUE,				/* partial_inplace */
    166  1.1  christos 	 0,				/* src_mask */
    167  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    168  1.1  christos 	 FALSE),			/* pcrel_offset */
    169  1.1  christos 
    170  1.1  christos   HOWTO (R_RISCV_TLS_DTPREL64,		/* type */
    171  1.1  christos 	 0,				/* rightshift */
    172  1.1  christos 	 4,				/* size */
    173  1.1  christos 	 64,				/* bitsize */
    174  1.1  christos 	 FALSE,				/* pc_relative */
    175  1.1  christos 	 0,				/* bitpos */
    176  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    177  1.1  christos 	 bfd_elf_generic_reloc, 	/* special_function */
    178  1.1  christos 	 "R_RISCV_TLS_DTPREL64",	/* name */
    179  1.1  christos 	 TRUE,				/* partial_inplace */
    180  1.1  christos 	 0,				/* src_mask */
    181  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    182  1.1  christos 	 FALSE),			/* pcrel_offset */
    183  1.1  christos 
    184  1.1  christos   HOWTO (R_RISCV_TLS_TPREL32,		/* type */
    185  1.1  christos 	 0,				/* rightshift */
    186  1.1  christos 	 2,				/* size */
    187  1.1  christos 	 32,				/* bitsize */
    188  1.1  christos 	 FALSE,				/* pc_relative */
    189  1.1  christos 	 0,				/* bitpos */
    190  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    191  1.1  christos 	 bfd_elf_generic_reloc, 	/* special_function */
    192  1.1  christos 	 "R_RISCV_TLS_TPREL32",		/* name */
    193  1.1  christos 	 FALSE,				/* partial_inplace */
    194  1.1  christos 	 0,				/* src_mask */
    195  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    196  1.1  christos 	 FALSE),			/* pcrel_offset */
    197  1.1  christos 
    198  1.1  christos   HOWTO (R_RISCV_TLS_TPREL64,		/* type */
    199  1.1  christos 	 0,				/* rightshift */
    200  1.1  christos 	 4,				/* size */
    201  1.1  christos 	 64,				/* bitsize */
    202  1.1  christos 	 FALSE,				/* pc_relative */
    203  1.1  christos 	 0,				/* bitpos */
    204  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    205  1.1  christos 	 bfd_elf_generic_reloc, 	/* special_function */
    206  1.1  christos 	 "R_RISCV_TLS_TPREL64",		/* name */
    207  1.1  christos 	 FALSE,				/* partial_inplace */
    208  1.1  christos 	 0,				/* src_mask */
    209  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    210  1.1  christos 	 FALSE),			/* pcrel_offset */
    211  1.1  christos 
    212  1.1  christos   /* Reserved for future relocs that the dynamic linker must understand.  */
    213  1.1  christos   EMPTY_HOWTO (12),
    214  1.1  christos   EMPTY_HOWTO (13),
    215  1.1  christos   EMPTY_HOWTO (14),
    216  1.1  christos   EMPTY_HOWTO (15),
    217  1.1  christos 
    218  1.1  christos   /* 12-bit PC-relative branch offset.  */
    219  1.1  christos   HOWTO (R_RISCV_BRANCH,		/* type */
    220  1.1  christos 	 0,				/* rightshift */
    221  1.1  christos 	 2,				/* size */
    222  1.1  christos 	 32,				/* bitsize */
    223  1.1  christos 	 TRUE,				/* pc_relative */
    224  1.1  christos 	 0,				/* bitpos */
    225  1.1  christos 	 complain_overflow_signed,	/* complain_on_overflow */
    226  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    227  1.1  christos 	 "R_RISCV_BRANCH",		/* name */
    228  1.1  christos 	 FALSE,				/* partial_inplace */
    229  1.1  christos 	 0,				/* src_mask */
    230  1.1  christos 	 ENCODE_SBTYPE_IMM (-1U),	/* dst_mask */
    231  1.1  christos 	 TRUE),				/* pcrel_offset */
    232  1.1  christos 
    233  1.1  christos   /* 20-bit PC-relative jump offset.  */
    234  1.1  christos   HOWTO (R_RISCV_JAL,			/* type */
    235  1.1  christos 	 0,				/* rightshift */
    236  1.1  christos 	 2,				/* size */
    237  1.1  christos 	 32,				/* bitsize */
    238  1.1  christos 	 TRUE,				/* pc_relative */
    239  1.1  christos 	 0,				/* bitpos */
    240  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    241  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    242  1.1  christos 	 "R_RISCV_JAL",			/* name */
    243  1.1  christos 	 FALSE,				/* partial_inplace */
    244  1.1  christos 	 0,				/* src_mask */
    245  1.1  christos 	 ENCODE_UJTYPE_IMM (-1U),	/* dst_mask */
    246  1.1  christos 	 TRUE),				/* pcrel_offset */
    247  1.1  christos 
    248  1.1  christos   /* 32-bit PC-relative function call (AUIPC/JALR).  */
    249  1.1  christos   HOWTO (R_RISCV_CALL,			/* type */
    250  1.1  christos 	 0,				/* rightshift */
    251  1.1  christos 	 2,				/* size */
    252  1.1  christos 	 64,				/* bitsize */
    253  1.1  christos 	 TRUE,				/* pc_relative */
    254  1.1  christos 	 0,				/* bitpos */
    255  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    256  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    257  1.1  christos 	 "R_RISCV_CALL",		/* name */
    258  1.1  christos 	 FALSE,				/* partial_inplace */
    259  1.1  christos 	 0,				/* src_mask */
    260  1.1  christos 	 ENCODE_UTYPE_IMM (-1U) | ((bfd_vma) ENCODE_ITYPE_IMM (-1U) << 32),
    261  1.1  christos 					/* dst_mask */
    262  1.1  christos 	 TRUE),				/* pcrel_offset */
    263  1.1  christos 
    264  1.1  christos   /* Like R_RISCV_CALL, but not locally binding.  */
    265  1.1  christos   HOWTO (R_RISCV_CALL_PLT,		/* type */
    266  1.1  christos 	 0,				/* rightshift */
    267  1.1  christos 	 2,				/* size */
    268  1.1  christos 	 64,				/* bitsize */
    269  1.1  christos 	 TRUE,				/* pc_relative */
    270  1.1  christos 	 0,				/* bitpos */
    271  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    272  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    273  1.1  christos 	 "R_RISCV_CALL_PLT",		/* name */
    274  1.1  christos 	 FALSE,				/* partial_inplace */
    275  1.1  christos 	 0,				/* src_mask */
    276  1.1  christos 	 ENCODE_UTYPE_IMM (-1U) | ((bfd_vma) ENCODE_ITYPE_IMM (-1U) << 32),
    277  1.1  christos 					/* dst_mask */
    278  1.1  christos 	 TRUE),				/* pcrel_offset */
    279  1.1  christos 
    280  1.1  christos   /* High 20 bits of 32-bit PC-relative GOT access.  */
    281  1.1  christos   HOWTO (R_RISCV_GOT_HI20,		/* type */
    282  1.1  christos 	 0,				/* rightshift */
    283  1.1  christos 	 2,				/* size */
    284  1.1  christos 	 32,				/* bitsize */
    285  1.1  christos 	 TRUE,				/* pc_relative */
    286  1.1  christos 	 0,				/* bitpos */
    287  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    288  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    289  1.1  christos 	 "R_RISCV_GOT_HI20",		/* name */
    290  1.1  christos 	 FALSE,				/* partial_inplace */
    291  1.1  christos 	 0,				/* src_mask */
    292  1.1  christos 	 ENCODE_UTYPE_IMM (-1U),	/* dst_mask */
    293  1.1  christos 	 FALSE),			/* pcrel_offset */
    294  1.1  christos 
    295  1.1  christos   /* High 20 bits of 32-bit PC-relative TLS IE GOT access.  */
    296  1.1  christos   HOWTO (R_RISCV_TLS_GOT_HI20,		/* type */
    297  1.1  christos 	 0,				/* rightshift */
    298  1.1  christos 	 2,				/* size */
    299  1.1  christos 	 32,				/* bitsize */
    300  1.1  christos 	 TRUE,				/* pc_relative */
    301  1.1  christos 	 0,				/* bitpos */
    302  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    303  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    304  1.1  christos 	 "R_RISCV_TLS_GOT_HI20",	/* name */
    305  1.1  christos 	 FALSE,				/* partial_inplace */
    306  1.1  christos 	 0,				/* src_mask */
    307  1.1  christos 	 ENCODE_UTYPE_IMM (-1U),	/* dst_mask */
    308  1.1  christos 	 FALSE),			/* pcrel_offset */
    309  1.1  christos 
    310  1.1  christos   /* High 20 bits of 32-bit PC-relative TLS GD GOT reference.  */
    311  1.1  christos   HOWTO (R_RISCV_TLS_GD_HI20,		/* type */
    312  1.1  christos 	 0,				/* rightshift */
    313  1.1  christos 	 2,				/* size */
    314  1.1  christos 	 32,				/* bitsize */
    315  1.1  christos 	 TRUE,				/* pc_relative */
    316  1.1  christos 	 0,				/* bitpos */
    317  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    318  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    319  1.1  christos 	 "R_RISCV_TLS_GD_HI20",		/* name */
    320  1.1  christos 	 FALSE,				/* partial_inplace */
    321  1.1  christos 	 0,				/* src_mask */
    322  1.1  christos 	 ENCODE_UTYPE_IMM (-1U),	/* dst_mask */
    323  1.1  christos 	 FALSE),			/* pcrel_offset */
    324  1.1  christos 
    325  1.1  christos   /* High 20 bits of 32-bit PC-relative reference.  */
    326  1.1  christos   HOWTO (R_RISCV_PCREL_HI20,		/* type */
    327  1.1  christos 	 0,				/* rightshift */
    328  1.1  christos 	 2,				/* size */
    329  1.1  christos 	 32,				/* bitsize */
    330  1.1  christos 	 TRUE,				/* pc_relative */
    331  1.1  christos 	 0,				/* bitpos */
    332  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    333  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    334  1.1  christos 	 "R_RISCV_PCREL_HI20",		/* name */
    335  1.1  christos 	 FALSE,				/* partial_inplace */
    336  1.1  christos 	 0,				/* src_mask */
    337  1.1  christos 	 ENCODE_UTYPE_IMM (-1U),	/* dst_mask */
    338  1.1  christos 	 TRUE),				/* pcrel_offset */
    339  1.1  christos 
    340  1.1  christos   /* Low 12 bits of a 32-bit PC-relative load or add.  */
    341  1.1  christos   HOWTO (R_RISCV_PCREL_LO12_I,		/* type */
    342  1.1  christos 	 0,				/* rightshift */
    343  1.1  christos 	 2,				/* size */
    344  1.1  christos 	 32,				/* bitsize */
    345  1.1  christos 	 FALSE,				/* pc_relative */
    346  1.1  christos 	 0,				/* bitpos */
    347  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    348  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    349  1.1  christos 	 "R_RISCV_PCREL_LO12_I",	/* name */
    350  1.1  christos 	 FALSE,				/* partial_inplace */
    351  1.1  christos 	 0,				/* src_mask */
    352  1.1  christos 	 ENCODE_ITYPE_IMM (-1U),	/* dst_mask */
    353  1.1  christos 	 FALSE),			/* pcrel_offset */
    354  1.1  christos 
    355  1.1  christos   /* Low 12 bits of a 32-bit PC-relative store.  */
    356  1.1  christos   HOWTO (R_RISCV_PCREL_LO12_S,		/* type */
    357  1.1  christos 	 0,				/* rightshift */
    358  1.1  christos 	 2,				/* size */
    359  1.1  christos 	 32,				/* bitsize */
    360  1.1  christos 	 FALSE,				/* pc_relative */
    361  1.1  christos 	 0,				/* bitpos */
    362  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    363  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    364  1.1  christos 	 "R_RISCV_PCREL_LO12_S",	/* name */
    365  1.1  christos 	 FALSE,				/* partial_inplace */
    366  1.1  christos 	 0,				/* src_mask */
    367  1.1  christos 	 ENCODE_STYPE_IMM (-1U),	/* dst_mask */
    368  1.1  christos 	 FALSE),			/* pcrel_offset */
    369  1.1  christos 
    370  1.1  christos   /* High 20 bits of 32-bit absolute address.  */
    371  1.1  christos   HOWTO (R_RISCV_HI20,			/* type */
    372  1.1  christos 	 0,				/* rightshift */
    373  1.1  christos 	 2,				/* size */
    374  1.1  christos 	 32,				/* bitsize */
    375  1.1  christos 	 FALSE,				/* pc_relative */
    376  1.1  christos 	 0,				/* bitpos */
    377  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    378  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    379  1.1  christos 	 "R_RISCV_HI20",		/* name */
    380  1.1  christos 	 FALSE,				/* partial_inplace */
    381  1.1  christos 	 0,				/* src_mask */
    382  1.1  christos 	 ENCODE_UTYPE_IMM (-1U),	/* dst_mask */
    383  1.1  christos 	 FALSE),			/* pcrel_offset */
    384  1.1  christos 
    385  1.1  christos   /* High 12 bits of 32-bit load or add.  */
    386  1.1  christos   HOWTO (R_RISCV_LO12_I,		/* type */
    387  1.1  christos 	 0,				/* rightshift */
    388  1.1  christos 	 2,				/* size */
    389  1.1  christos 	 32,				/* bitsize */
    390  1.1  christos 	 FALSE,				/* pc_relative */
    391  1.1  christos 	 0,				/* bitpos */
    392  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    393  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    394  1.1  christos 	 "R_RISCV_LO12_I",		/* name */
    395  1.1  christos 	 FALSE,				/* partial_inplace */
    396  1.1  christos 	 0,				/* src_mask */
    397  1.1  christos 	 ENCODE_ITYPE_IMM (-1U),	/* dst_mask */
    398  1.1  christos 	 FALSE),			/* pcrel_offset */
    399  1.1  christos 
    400  1.1  christos   /* High 12 bits of 32-bit store.  */
    401  1.1  christos   HOWTO (R_RISCV_LO12_S,		/* type */
    402  1.1  christos 	 0,				/* rightshift */
    403  1.1  christos 	 2,				/* size */
    404  1.1  christos 	 32,				/* bitsize */
    405  1.1  christos 	 FALSE,				/* pc_relative */
    406  1.1  christos 	 0,				/* bitpos */
    407  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    408  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    409  1.1  christos 	 "R_RISCV_LO12_S",		/* name */
    410  1.1  christos 	 FALSE,				/* partial_inplace */
    411  1.1  christos 	 0,				/* src_mask */
    412  1.1  christos 	 ENCODE_STYPE_IMM (-1U),	/* dst_mask */
    413  1.1  christos 	 FALSE),			/* pcrel_offset */
    414  1.1  christos 
    415  1.1  christos   /* High 20 bits of TLS LE thread pointer offset.  */
    416  1.1  christos   HOWTO (R_RISCV_TPREL_HI20,		/* type */
    417  1.1  christos 	 0,				/* rightshift */
    418  1.1  christos 	 2,				/* size */
    419  1.1  christos 	 32,				/* bitsize */
    420  1.1  christos 	 FALSE,				/* pc_relative */
    421  1.1  christos 	 0,				/* bitpos */
    422  1.1  christos 	 complain_overflow_signed,	/* complain_on_overflow */
    423  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    424  1.1  christos 	 "R_RISCV_TPREL_HI20",		/* name */
    425  1.1  christos 	 TRUE,				/* partial_inplace */
    426  1.1  christos 	 0,				/* src_mask */
    427  1.1  christos 	 ENCODE_UTYPE_IMM (-1U),	/* dst_mask */
    428  1.1  christos 	 FALSE),			/* pcrel_offset */
    429  1.1  christos 
    430  1.1  christos   /* Low 12 bits of TLS LE thread pointer offset for loads and adds.  */
    431  1.1  christos   HOWTO (R_RISCV_TPREL_LO12_I,		/* type */
    432  1.1  christos 	 0,				/* rightshift */
    433  1.1  christos 	 2,				/* size */
    434  1.1  christos 	 32,				/* bitsize */
    435  1.1  christos 	 FALSE,				/* pc_relative */
    436  1.1  christos 	 0,				/* bitpos */
    437  1.1  christos 	 complain_overflow_signed,	/* complain_on_overflow */
    438  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    439  1.1  christos 	 "R_RISCV_TPREL_LO12_I",	/* name */
    440  1.1  christos 	 FALSE,				/* partial_inplace */
    441  1.1  christos 	 0,				/* src_mask */
    442  1.1  christos 	 ENCODE_ITYPE_IMM (-1U),	/* dst_mask */
    443  1.1  christos 	 FALSE),			/* pcrel_offset */
    444  1.1  christos 
    445  1.1  christos   /* Low 12 bits of TLS LE thread pointer offset for stores.  */
    446  1.1  christos   HOWTO (R_RISCV_TPREL_LO12_S,		/* type */
    447  1.1  christos 	 0,				/* rightshift */
    448  1.1  christos 	 2,				/* size */
    449  1.1  christos 	 32,				/* bitsize */
    450  1.1  christos 	 FALSE,				/* pc_relative */
    451  1.1  christos 	 0,				/* bitpos */
    452  1.1  christos 	 complain_overflow_signed,	/* complain_on_overflow */
    453  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    454  1.1  christos 	 "R_RISCV_TPREL_LO12_S",	/* name */
    455  1.1  christos 	 FALSE,				/* partial_inplace */
    456  1.1  christos 	 0,				/* src_mask */
    457  1.1  christos 	 ENCODE_STYPE_IMM (-1U),	/* dst_mask */
    458  1.1  christos 	 FALSE),			/* pcrel_offset */
    459  1.1  christos 
    460  1.1  christos   /* TLS LE thread pointer usage.  May be relaxed.  */
    461  1.1  christos   HOWTO (R_RISCV_TPREL_ADD,		/* type */
    462  1.1  christos 	 0,				/* rightshift */
    463  1.1  christos 	 2,				/* size */
    464  1.1  christos 	 32,				/* bitsize */
    465  1.1  christos 	 FALSE,				/* pc_relative */
    466  1.1  christos 	 0,				/* bitpos */
    467  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    468  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    469  1.1  christos 	 "R_RISCV_TPREL_ADD",		/* name */
    470  1.1  christos 	 TRUE,				/* partial_inplace */
    471  1.1  christos 	 0,				/* src_mask */
    472  1.1  christos 	 0,				/* dst_mask */
    473  1.1  christos 	 FALSE),			/* pcrel_offset */
    474  1.1  christos 
    475  1.1  christos   /* 8-bit in-place addition, for local label subtraction.  */
    476  1.1  christos   HOWTO (R_RISCV_ADD8,			/* type */
    477  1.1  christos 	 0,				/* rightshift */
    478  1.1  christos 	 0,				/* size */
    479  1.1  christos 	 8,				/* bitsize */
    480  1.1  christos 	 FALSE,				/* pc_relative */
    481  1.1  christos 	 0,				/* bitpos */
    482  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    483  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    484  1.1  christos 	 "R_RISCV_ADD8",		/* name */
    485  1.1  christos 	 FALSE,				/* partial_inplace */
    486  1.1  christos 	 0,				/* src_mask */
    487  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    488  1.1  christos 	 FALSE),			/* pcrel_offset */
    489  1.1  christos 
    490  1.1  christos   /* 16-bit in-place addition, for local label subtraction.  */
    491  1.1  christos   HOWTO (R_RISCV_ADD16,			/* type */
    492  1.1  christos 	 0,				/* rightshift */
    493  1.1  christos 	 1,				/* size */
    494  1.1  christos 	 16,				/* bitsize */
    495  1.1  christos 	 FALSE,				/* pc_relative */
    496  1.1  christos 	 0,				/* bitpos */
    497  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    498  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    499  1.1  christos 	 "R_RISCV_ADD16",		/* name */
    500  1.1  christos 	 FALSE,				/* partial_inplace */
    501  1.1  christos 	 0,				/* src_mask */
    502  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    503  1.1  christos 	 FALSE),			/* pcrel_offset */
    504  1.1  christos 
    505  1.1  christos   /* 32-bit in-place addition, for local label subtraction.  */
    506  1.1  christos   HOWTO (R_RISCV_ADD32,			/* type */
    507  1.1  christos 	 0,				/* rightshift */
    508  1.1  christos 	 2,				/* size */
    509  1.1  christos 	 32,				/* bitsize */
    510  1.1  christos 	 FALSE,				/* pc_relative */
    511  1.1  christos 	 0,				/* bitpos */
    512  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    513  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    514  1.1  christos 	 "R_RISCV_ADD32",		/* name */
    515  1.1  christos 	 FALSE,				/* partial_inplace */
    516  1.1  christos 	 0,				/* src_mask */
    517  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    518  1.1  christos 	 FALSE),			/* pcrel_offset */
    519  1.1  christos 
    520  1.1  christos   /* 64-bit in-place addition, for local label subtraction.  */
    521  1.1  christos   HOWTO (R_RISCV_ADD64,			/* type */
    522  1.1  christos 	 0,				/* rightshift */
    523  1.1  christos 	 4,				/* size */
    524  1.1  christos 	 64,				/* bitsize */
    525  1.1  christos 	 FALSE,				/* pc_relative */
    526  1.1  christos 	 0,				/* bitpos */
    527  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    528  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    529  1.1  christos 	 "R_RISCV_ADD64",		/* name */
    530  1.1  christos 	 FALSE,				/* partial_inplace */
    531  1.1  christos 	 0,				/* src_mask */
    532  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    533  1.1  christos 	 FALSE),			/* pcrel_offset */
    534  1.1  christos 
    535  1.1  christos   /* 8-bit in-place addition, for local label subtraction.  */
    536  1.1  christos   HOWTO (R_RISCV_SUB8,			/* type */
    537  1.1  christos 	 0,				/* rightshift */
    538  1.1  christos 	 0,				/* size */
    539  1.1  christos 	 8,				/* bitsize */
    540  1.1  christos 	 FALSE,				/* pc_relative */
    541  1.1  christos 	 0,				/* bitpos */
    542  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    543  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    544  1.1  christos 	 "R_RISCV_SUB8",		/* name */
    545  1.1  christos 	 FALSE,				/* partial_inplace */
    546  1.1  christos 	 0,				/* src_mask */
    547  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    548  1.1  christos 	 FALSE),			/* pcrel_offset */
    549  1.1  christos 
    550  1.1  christos   /* 16-bit in-place addition, for local label subtraction.  */
    551  1.1  christos   HOWTO (R_RISCV_SUB16,			/* type */
    552  1.1  christos 	 0,				/* rightshift */
    553  1.1  christos 	 1,				/* size */
    554  1.1  christos 	 16,				/* bitsize */
    555  1.1  christos 	 FALSE,				/* pc_relative */
    556  1.1  christos 	 0,				/* bitpos */
    557  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    558  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    559  1.1  christos 	 "R_RISCV_SUB16",		/* name */
    560  1.1  christos 	 FALSE,				/* partial_inplace */
    561  1.1  christos 	 0,				/* src_mask */
    562  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    563  1.1  christos 	 FALSE),			/* pcrel_offset */
    564  1.1  christos 
    565  1.1  christos   /* 32-bit in-place addition, for local label subtraction.  */
    566  1.1  christos   HOWTO (R_RISCV_SUB32,			/* type */
    567  1.1  christos 	 0,				/* rightshift */
    568  1.1  christos 	 2,				/* size */
    569  1.1  christos 	 32,				/* bitsize */
    570  1.1  christos 	 FALSE,				/* pc_relative */
    571  1.1  christos 	 0,				/* bitpos */
    572  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    573  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    574  1.1  christos 	 "R_RISCV_SUB32",		/* name */
    575  1.1  christos 	 FALSE,				/* partial_inplace */
    576  1.1  christos 	 0,				/* src_mask */
    577  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    578  1.1  christos 	 FALSE),			/* pcrel_offset */
    579  1.1  christos 
    580  1.1  christos   /* 64-bit in-place addition, for local label subtraction.  */
    581  1.1  christos   HOWTO (R_RISCV_SUB64,			/* type */
    582  1.1  christos 	 0,				/* rightshift */
    583  1.1  christos 	 4,				/* size */
    584  1.1  christos 	 64,				/* bitsize */
    585  1.1  christos 	 FALSE,				/* pc_relative */
    586  1.1  christos 	 0,				/* bitpos */
    587  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    588  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    589  1.1  christos 	 "R_RISCV_SUB64",		/* name */
    590  1.1  christos 	 FALSE,				/* partial_inplace */
    591  1.1  christos 	 0,				/* src_mask */
    592  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    593  1.1  christos 	 FALSE),			/* pcrel_offset */
    594  1.1  christos 
    595  1.1  christos   /* GNU extension to record C++ vtable hierarchy */
    596  1.1  christos   HOWTO (R_RISCV_GNU_VTINHERIT,		/* type */
    597  1.1  christos 	 0,				/* rightshift */
    598  1.1  christos 	 4,				/* size */
    599  1.1  christos 	 0,				/* bitsize */
    600  1.1  christos 	 FALSE,				/* pc_relative */
    601  1.1  christos 	 0,				/* bitpos */
    602  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    603  1.1  christos 	 NULL,				/* special_function */
    604  1.1  christos 	 "R_RISCV_GNU_VTINHERIT",	/* name */
    605  1.1  christos 	 FALSE,				/* partial_inplace */
    606  1.1  christos 	 0,				/* src_mask */
    607  1.1  christos 	 0,				/* dst_mask */
    608  1.1  christos 	 FALSE),			/* pcrel_offset */
    609  1.1  christos 
    610  1.1  christos   /* GNU extension to record C++ vtable member usage */
    611  1.1  christos   HOWTO (R_RISCV_GNU_VTENTRY,		/* type */
    612  1.1  christos 	 0,				/* rightshift */
    613  1.1  christos 	 4,				/* size */
    614  1.1  christos 	 0,				/* bitsize */
    615  1.1  christos 	 FALSE,				/* pc_relative */
    616  1.1  christos 	 0,				/* bitpos */
    617  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    618  1.1  christos 	 _bfd_elf_rel_vtable_reloc_fn,	/* special_function */
    619  1.1  christos 	 "R_RISCV_GNU_VTENTRY",		/* name */
    620  1.1  christos 	 FALSE,				/* partial_inplace */
    621  1.1  christos 	 0,				/* src_mask */
    622  1.1  christos 	 0,				/* dst_mask */
    623  1.1  christos 	 FALSE),			/* pcrel_offset */
    624  1.1  christos 
    625  1.1  christos   /* Indicates an alignment statement.  The addend field encodes how many
    626  1.1  christos      bytes of NOPs follow the statement.  The desired alignment is the
    627  1.1  christos      addend rounded up to the next power of two.  */
    628  1.1  christos   HOWTO (R_RISCV_ALIGN,			/* type */
    629  1.1  christos 	 0,				/* rightshift */
    630  1.1  christos 	 2,				/* size */
    631  1.1  christos 	 0,				/* bitsize */
    632  1.1  christos 	 FALSE,				/* pc_relative */
    633  1.1  christos 	 0,				/* bitpos */
    634  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    635  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    636  1.1  christos 	 "R_RISCV_ALIGN",		/* name */
    637  1.1  christos 	 FALSE,				/* partial_inplace */
    638  1.1  christos 	 0,				/* src_mask */
    639  1.1  christos 	 0,				/* dst_mask */
    640  1.1  christos 	 TRUE),				/* pcrel_offset */
    641  1.1  christos 
    642  1.1  christos   /* 8-bit PC-relative branch offset.  */
    643  1.1  christos   HOWTO (R_RISCV_RVC_BRANCH,		/* type */
    644  1.1  christos 	 0,				/* rightshift */
    645  1.1  christos 	 2,				/* size */
    646  1.1  christos 	 32,				/* bitsize */
    647  1.1  christos 	 TRUE,				/* pc_relative */
    648  1.1  christos 	 0,				/* bitpos */
    649  1.1  christos 	 complain_overflow_signed,	/* complain_on_overflow */
    650  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    651  1.1  christos 	 "R_RISCV_RVC_BRANCH",		/* name */
    652  1.1  christos 	 FALSE,				/* partial_inplace */
    653  1.1  christos 	 0,				/* src_mask */
    654  1.1  christos 	 ENCODE_RVC_B_IMM (-1U),	/* dst_mask */
    655  1.1  christos 	 TRUE),				/* pcrel_offset */
    656  1.1  christos 
    657  1.1  christos   /* 11-bit PC-relative jump offset.  */
    658  1.1  christos   HOWTO (R_RISCV_RVC_JUMP,		/* type */
    659  1.1  christos 	 0,				/* rightshift */
    660  1.1  christos 	 2,				/* size */
    661  1.1  christos 	 32,				/* bitsize */
    662  1.1  christos 	 TRUE,				/* pc_relative */
    663  1.1  christos 	 0,				/* bitpos */
    664  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    665  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    666  1.1  christos 	 "R_RISCV_RVC_JUMP",		/* name */
    667  1.1  christos 	 FALSE,				/* partial_inplace */
    668  1.1  christos 	 0,				/* src_mask */
    669  1.1  christos 	 ENCODE_RVC_J_IMM (-1U),	/* dst_mask */
    670  1.1  christos 	 TRUE),				/* pcrel_offset */
    671  1.1  christos 
    672  1.1  christos   /* High 6 bits of 18-bit absolute address.  */
    673  1.1  christos   HOWTO (R_RISCV_RVC_LUI,		/* type */
    674  1.1  christos 	 0,				/* rightshift */
    675  1.1  christos 	 2,				/* size */
    676  1.1  christos 	 32,				/* bitsize */
    677  1.1  christos 	 FALSE,				/* pc_relative */
    678  1.1  christos 	 0,				/* bitpos */
    679  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    680  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    681  1.1  christos 	 "R_RISCV_RVC_LUI",		/* name */
    682  1.1  christos 	 FALSE,				/* partial_inplace */
    683  1.1  christos 	 0,				/* src_mask */
    684  1.1  christos 	 ENCODE_RVC_IMM (-1U),		/* dst_mask */
    685  1.1  christos 	 FALSE),			/* pcrel_offset */
    686  1.1  christos 
    687  1.1  christos   /* GP-relative load.  */
    688  1.1  christos   HOWTO (R_RISCV_GPREL_I,		/* type */
    689  1.1  christos 	 0,				/* rightshift */
    690  1.1  christos 	 2,				/* size */
    691  1.1  christos 	 32,				/* bitsize */
    692  1.1  christos 	 FALSE,				/* pc_relative */
    693  1.1  christos 	 0,				/* bitpos */
    694  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    695  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    696  1.1  christos 	 "R_RISCV_GPREL_I",		/* name */
    697  1.1  christos 	 FALSE,				/* partial_inplace */
    698  1.1  christos 	 0,				/* src_mask */
    699  1.1  christos 	 ENCODE_ITYPE_IMM (-1U),	/* dst_mask */
    700  1.1  christos 	 FALSE),			/* pcrel_offset */
    701  1.1  christos 
    702  1.1  christos   /* GP-relative store.  */
    703  1.1  christos   HOWTO (R_RISCV_GPREL_S,		/* type */
    704  1.1  christos 	 0,				/* rightshift */
    705  1.1  christos 	 2,				/* size */
    706  1.1  christos 	 32,				/* bitsize */
    707  1.1  christos 	 FALSE,				/* pc_relative */
    708  1.1  christos 	 0,				/* bitpos */
    709  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    710  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    711  1.1  christos 	 "R_RISCV_GPREL_S",		/* name */
    712  1.1  christos 	 FALSE,				/* partial_inplace */
    713  1.1  christos 	 0,				/* src_mask */
    714  1.1  christos 	 ENCODE_STYPE_IMM (-1U),	/* dst_mask */
    715  1.1  christos 	 FALSE),			/* pcrel_offset */
    716  1.1  christos 
    717  1.1  christos   /* TP-relative TLS LE load.  */
    718  1.1  christos   HOWTO (R_RISCV_TPREL_I,		/* type */
    719  1.1  christos 	 0,				/* rightshift */
    720  1.1  christos 	 2,				/* size */
    721  1.1  christos 	 32,				/* bitsize */
    722  1.1  christos 	 FALSE,				/* pc_relative */
    723  1.1  christos 	 0,				/* bitpos */
    724  1.1  christos 	 complain_overflow_signed,	/* complain_on_overflow */
    725  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    726  1.1  christos 	 "R_RISCV_TPREL_I",		/* name */
    727  1.1  christos 	 FALSE,				/* partial_inplace */
    728  1.1  christos 	 0,				/* src_mask */
    729  1.1  christos 	 ENCODE_ITYPE_IMM (-1U),	/* dst_mask */
    730  1.1  christos 	 FALSE),			/* pcrel_offset */
    731  1.1  christos 
    732  1.1  christos   /* TP-relative TLS LE store.  */
    733  1.1  christos   HOWTO (R_RISCV_TPREL_S,		/* type */
    734  1.1  christos 	 0,				/* rightshift */
    735  1.1  christos 	 2,				/* size */
    736  1.1  christos 	 32,				/* bitsize */
    737  1.1  christos 	 FALSE,				/* pc_relative */
    738  1.1  christos 	 0,				/* bitpos */
    739  1.1  christos 	 complain_overflow_signed,	/* complain_on_overflow */
    740  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    741  1.1  christos 	 "R_RISCV_TPREL_S",		/* name */
    742  1.1  christos 	 FALSE,				/* partial_inplace */
    743  1.1  christos 	 0,				/* src_mask */
    744  1.1  christos 	 ENCODE_STYPE_IMM (-1U),	/* dst_mask */
    745  1.1  christos 	 FALSE),			/* pcrel_offset */
    746  1.1  christos 
    747  1.1  christos   /* The paired relocation may be relaxed.  */
    748  1.1  christos   HOWTO (R_RISCV_RELAX,			/* type */
    749  1.1  christos 	 0,				/* rightshift */
    750  1.1  christos 	 3,				/* size */
    751  1.1  christos 	 0,				/* bitsize */
    752  1.1  christos 	 FALSE,				/* pc_relative */
    753  1.1  christos 	 0,				/* bitpos */
    754  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    755  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    756  1.1  christos 	 "R_RISCV_RELAX",		/* name */
    757  1.1  christos 	 FALSE,				/* partial_inplace */
    758  1.1  christos 	 0,				/* src_mask */
    759  1.1  christos 	 0,				/* dst_mask */
    760  1.1  christos 	 FALSE),			/* pcrel_offset */
    761  1.1  christos 
    762  1.1  christos   /* 6-bit in-place addition, for local label subtraction.  */
    763  1.1  christos   HOWTO (R_RISCV_SUB6,			/* type */
    764  1.1  christos 	 0,				/* rightshift */
    765  1.1  christos 	 0,				/* size */
    766  1.1  christos 	 8,				/* bitsize */
    767  1.1  christos 	 FALSE,				/* pc_relative */
    768  1.1  christos 	 0,				/* bitpos */
    769  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    770  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    771  1.1  christos 	 "R_RISCV_SUB6",		/* name */
    772  1.1  christos 	 FALSE,				/* partial_inplace */
    773  1.1  christos 	 0,				/* src_mask */
    774  1.1  christos 	 0x3f,				/* dst_mask */
    775  1.1  christos 	 FALSE),			/* pcrel_offset */
    776  1.1  christos 
    777  1.1  christos   /* 6-bit in-place setting, for local label subtraction.  */
    778  1.1  christos   HOWTO (R_RISCV_SET6,			/* type */
    779  1.1  christos 	 0,				/* rightshift */
    780  1.1  christos 	 0,				/* size */
    781  1.1  christos 	 8,				/* bitsize */
    782  1.1  christos 	 FALSE,				/* pc_relative */
    783  1.1  christos 	 0,				/* bitpos */
    784  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    785  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    786  1.1  christos 	 "R_RISCV_SET6",		/* name */
    787  1.1  christos 	 FALSE,				/* partial_inplace */
    788  1.1  christos 	 0,				/* src_mask */
    789  1.1  christos 	 0x3f,				/* dst_mask */
    790  1.1  christos 	 FALSE),			/* pcrel_offset */
    791  1.1  christos 
    792  1.1  christos   /* 8-bit in-place setting, for local label subtraction.  */
    793  1.1  christos   HOWTO (R_RISCV_SET8,			/* type */
    794  1.1  christos 	 0,				/* rightshift */
    795  1.1  christos 	 0,				/* size */
    796  1.1  christos 	 8,				/* bitsize */
    797  1.1  christos 	 FALSE,				/* pc_relative */
    798  1.1  christos 	 0,				/* bitpos */
    799  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    800  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    801  1.1  christos 	 "R_RISCV_SET8",		/* name */
    802  1.1  christos 	 FALSE,				/* partial_inplace */
    803  1.1  christos 	 0,				/* src_mask */
    804  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    805  1.1  christos 	 FALSE),			/* pcrel_offset */
    806  1.1  christos 
    807  1.1  christos   /* 16-bit in-place setting, for local label subtraction.  */
    808  1.1  christos   HOWTO (R_RISCV_SET16,			/* type */
    809  1.1  christos 	 0,				/* rightshift */
    810  1.1  christos 	 1,				/* size */
    811  1.1  christos 	 16,				/* bitsize */
    812  1.1  christos 	 FALSE,				/* pc_relative */
    813  1.1  christos 	 0,				/* bitpos */
    814  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    815  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    816  1.1  christos 	 "R_RISCV_SET16",		/* name */
    817  1.1  christos 	 FALSE,				/* partial_inplace */
    818  1.1  christos 	 0,				/* src_mask */
    819  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    820  1.1  christos 	 FALSE),			/* pcrel_offset */
    821  1.1  christos 
    822  1.1  christos   /* 32-bit in-place setting, for local label subtraction.  */
    823  1.1  christos   HOWTO (R_RISCV_SET32,			/* type */
    824  1.1  christos 	 0,				/* rightshift */
    825  1.1  christos 	 2,				/* size */
    826  1.1  christos 	 32,				/* bitsize */
    827  1.1  christos 	 FALSE,				/* pc_relative */
    828  1.1  christos 	 0,				/* bitpos */
    829  1.1  christos 	 complain_overflow_dont,	/* complain_on_overflow */
    830  1.1  christos 	 bfd_elf_generic_reloc,		/* special_function */
    831  1.1  christos 	 "R_RISCV_SET32",		/* name */
    832  1.1  christos 	 FALSE,				/* partial_inplace */
    833  1.1  christos 	 0,				/* src_mask */
    834  1.1  christos 	 MINUS_ONE,			/* dst_mask */
    835  1.1  christos 	 FALSE),			/* pcrel_offset */
    836  1.1  christos };
    837  1.1  christos 
    838  1.1  christos /* A mapping from BFD reloc types to RISC-V ELF reloc types.  */
    839  1.1  christos 
    840  1.1  christos struct elf_reloc_map
    841  1.1  christos {
    842  1.1  christos   bfd_reloc_code_real_type bfd_val;
    843  1.1  christos   enum elf_riscv_reloc_type elf_val;
    844  1.1  christos };
    845  1.1  christos 
    846  1.1  christos static const struct elf_reloc_map riscv_reloc_map[] =
    847  1.1  christos {
    848  1.1  christos   { BFD_RELOC_NONE, R_RISCV_NONE },
    849  1.1  christos   { BFD_RELOC_32, R_RISCV_32 },
    850  1.1  christos   { BFD_RELOC_64, R_RISCV_64 },
    851  1.1  christos   { BFD_RELOC_RISCV_ADD8, R_RISCV_ADD8 },
    852  1.1  christos   { BFD_RELOC_RISCV_ADD16, R_RISCV_ADD16 },
    853  1.1  christos   { BFD_RELOC_RISCV_ADD32, R_RISCV_ADD32 },
    854  1.1  christos   { BFD_RELOC_RISCV_ADD64, R_RISCV_ADD64 },
    855  1.1  christos   { BFD_RELOC_RISCV_SUB8, R_RISCV_SUB8 },
    856  1.1  christos   { BFD_RELOC_RISCV_SUB16, R_RISCV_SUB16 },
    857  1.1  christos   { BFD_RELOC_RISCV_SUB32, R_RISCV_SUB32 },
    858  1.1  christos   { BFD_RELOC_RISCV_SUB64, R_RISCV_SUB64 },
    859  1.1  christos   { BFD_RELOC_CTOR, R_RISCV_64 },
    860  1.1  christos   { BFD_RELOC_12_PCREL, R_RISCV_BRANCH },
    861  1.1  christos   { BFD_RELOC_RISCV_HI20, R_RISCV_HI20 },
    862  1.1  christos   { BFD_RELOC_RISCV_LO12_I, R_RISCV_LO12_I },
    863  1.1  christos   { BFD_RELOC_RISCV_LO12_S, R_RISCV_LO12_S },
    864  1.1  christos   { BFD_RELOC_RISCV_PCREL_LO12_I, R_RISCV_PCREL_LO12_I },
    865  1.1  christos   { BFD_RELOC_RISCV_PCREL_LO12_S, R_RISCV_PCREL_LO12_S },
    866  1.1  christos   { BFD_RELOC_RISCV_CALL, R_RISCV_CALL },
    867  1.1  christos   { BFD_RELOC_RISCV_CALL_PLT, R_RISCV_CALL_PLT },
    868  1.1  christos   { BFD_RELOC_RISCV_PCREL_HI20, R_RISCV_PCREL_HI20 },
    869  1.1  christos   { BFD_RELOC_RISCV_JMP, R_RISCV_JAL },
    870  1.1  christos   { BFD_RELOC_RISCV_GOT_HI20, R_RISCV_GOT_HI20 },
    871  1.1  christos   { BFD_RELOC_RISCV_TLS_DTPMOD32, R_RISCV_TLS_DTPMOD32 },
    872  1.1  christos   { BFD_RELOC_RISCV_TLS_DTPREL32, R_RISCV_TLS_DTPREL32 },
    873  1.1  christos   { BFD_RELOC_RISCV_TLS_DTPMOD64, R_RISCV_TLS_DTPMOD64 },
    874  1.1  christos   { BFD_RELOC_RISCV_TLS_DTPREL64, R_RISCV_TLS_DTPREL64 },
    875  1.1  christos   { BFD_RELOC_RISCV_TLS_TPREL32, R_RISCV_TLS_TPREL32 },
    876  1.1  christos   { BFD_RELOC_RISCV_TLS_TPREL64, R_RISCV_TLS_TPREL64 },
    877  1.1  christos   { BFD_RELOC_RISCV_TPREL_HI20, R_RISCV_TPREL_HI20 },
    878  1.1  christos   { BFD_RELOC_RISCV_TPREL_ADD, R_RISCV_TPREL_ADD },
    879  1.1  christos   { BFD_RELOC_RISCV_TPREL_LO12_S, R_RISCV_TPREL_LO12_S },
    880  1.1  christos   { BFD_RELOC_RISCV_TPREL_LO12_I, R_RISCV_TPREL_LO12_I },
    881  1.1  christos   { BFD_RELOC_RISCV_TLS_GOT_HI20, R_RISCV_TLS_GOT_HI20 },
    882  1.1  christos   { BFD_RELOC_RISCV_TLS_GD_HI20, R_RISCV_TLS_GD_HI20 },
    883  1.1  christos   { BFD_RELOC_RISCV_ALIGN, R_RISCV_ALIGN },
    884  1.1  christos   { BFD_RELOC_RISCV_RVC_BRANCH, R_RISCV_RVC_BRANCH },
    885  1.1  christos   { BFD_RELOC_RISCV_RVC_JUMP, R_RISCV_RVC_JUMP },
    886  1.1  christos   { BFD_RELOC_RISCV_RVC_LUI, R_RISCV_RVC_LUI },
    887  1.1  christos   { BFD_RELOC_RISCV_GPREL_I, R_RISCV_GPREL_I },
    888  1.1  christos   { BFD_RELOC_RISCV_GPREL_S, R_RISCV_GPREL_S },
    889  1.1  christos   { BFD_RELOC_RISCV_TPREL_I, R_RISCV_TPREL_I },
    890  1.1  christos   { BFD_RELOC_RISCV_TPREL_S, R_RISCV_TPREL_S },
    891  1.1  christos   { BFD_RELOC_RISCV_RELAX, R_RISCV_RELAX },
    892  1.1  christos   { BFD_RELOC_RISCV_SUB6, R_RISCV_SUB6 },
    893  1.1  christos   { BFD_RELOC_RISCV_SET6, R_RISCV_SET6 },
    894  1.1  christos   { BFD_RELOC_RISCV_SET8, R_RISCV_SET8 },
    895  1.1  christos   { BFD_RELOC_RISCV_SET16, R_RISCV_SET16 },
    896  1.1  christos   { BFD_RELOC_RISCV_SET32, R_RISCV_SET32 },
    897  1.1  christos };
    898  1.1  christos 
    899  1.1  christos /* Given a BFD reloc type, return a howto structure.  */
    900  1.1  christos 
    901  1.1  christos reloc_howto_type *
    902  1.1  christos riscv_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    903  1.1  christos 			 bfd_reloc_code_real_type code)
    904  1.1  christos {
    905  1.1  christos   unsigned int i;
    906  1.1  christos 
    907  1.1  christos   for (i = 0; i < ARRAY_SIZE (riscv_reloc_map); i++)
    908  1.1  christos     if (riscv_reloc_map[i].bfd_val == code)
    909  1.1  christos       return &howto_table[(int) riscv_reloc_map[i].elf_val];
    910  1.1  christos 
    911  1.1  christos   bfd_set_error (bfd_error_bad_value);
    912  1.1  christos   return NULL;
    913  1.1  christos }
    914  1.1  christos 
    915  1.1  christos reloc_howto_type *
    916  1.1  christos riscv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
    917  1.1  christos {
    918  1.1  christos   unsigned int i;
    919  1.1  christos 
    920  1.1  christos   for (i = 0; i < ARRAY_SIZE (howto_table); i++)
    921  1.1  christos     if (howto_table[i].name && strcasecmp (howto_table[i].name, r_name) == 0)
    922  1.1  christos       return &howto_table[i];
    923  1.1  christos 
    924  1.1  christos   return NULL;
    925  1.1  christos }
    926  1.1  christos 
    927  1.1  christos reloc_howto_type *
    928  1.1  christos riscv_elf_rtype_to_howto (unsigned int r_type)
    929  1.1  christos {
    930  1.1  christos   if (r_type >= ARRAY_SIZE (howto_table))
    931  1.1  christos     {
    932  1.1  christos       (*_bfd_error_handler) (_("unrecognized relocation (0x%x)"), r_type);
    933  1.1  christos       bfd_set_error (bfd_error_bad_value);
    934  1.1  christos       return NULL;
    935  1.1  christos     }
    936  1.1  christos   return &howto_table[r_type];
    937  1.1  christos }
    938