• Flag to ignore main:
--defsym=main=0x100
  • To ignore _start:
-nostartfiles

RelocID Pass

  • *howto:
{type = 224, size = 2, bitsize = 32, rightshift = 1, bitpos = 0, complain_on_overflow = complain_overflow_unsigned, negate = 0, pc_relative = 1, partial_inplace = 0, pcrel_offset = 1, src_mask = 0, dst_mask = 4293918720, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7506 "R_RISCV_CVPCREL_UI12"}
  • *rel:
{r_offset = 2, r_info = 1504, r_addend = 0}
  • value: 3145728

We first do CVPCREL with the *howto:

{type = 224, size = 2, bitsize = 32, rightshift = 1, bitpos = 0, complain_on_overflow = complain_overflow_unsigned, negate = 0, pc_relative = 1, partial_inplace = 0, pcrel_offset = 1, src_mask = 0, dst_mask = 4293918720, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7506 "R_RISCV_CVPCREL_UI12"}

Value is set to 6.

Then we get to RELOCID:

{type = 59, size = 3, bitsize = 32, rightshift = 0, bitpos = 0, complain_on_overflow = complain_overflow_dont, negate = 0, pc_relative = 0, partial_inplace = 0, pcrel_offset = 0, src_mask = 0, dst_mask = 0, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7530 "R_RISCV_RELOCID"}

value += rel->r_addend therefore 100 (the ID).

We get the previous relocation:

int prev_reloc = ELFNN_R_TYPE ((rel - 1))->r_info);

The howto turns into:

{type = 224, size = 2, bitsize = 32, rightshift = 1, bitpos = 0, complain_on_overflow = complain_overflow_unsigned, negate = 0, pc_relative = 1, partial_inplace = 0, pcrel_offset = 1, src_mask = 0, dst_mask = 4293918720, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7506 "R_RISCV_CVPCREL_UI12"}

And word is 3145851.

rel however, still points to RELOCID and not CVPCREL. I don’t seem able to change the value (or addend) without accessing the actual relocation.

We go to riscv_elf_rtype_to_howto which looks for relocation 224 in the howto table and returns its location (&howto_table[i]).

When we get to r_type = 58, it jumps to 224. Therefore, it replaces RELOCID with CVPCREL in the howto table (RELOCID points to CVPCREL).

The address being returned is:

(const reloc_howto_type *) 0x5555559043b8 <howto_table+2360>

We are then sent to elfnn-riscv.c:1765 aka the default of perform_relocation: return bfd_reloc_notsupported.

If I use the riscv_reloc_type_lookup function, then prev_reloc somehow points to BFD_RELOC_MICROMIPS_GPREL16. It seems to only get

HOWTO

The howto field can be imagined as a relocation instruction. It is a pointer to a structure which contains information on what to do with all of the other information in the relocation record and data section. A back end would normally have a relocation instruction set and turn relocations into pointers to the correct structure on input - but it would be possible to create each howto field on demand.

  • daily
  • work/relocation-prototype programming-languages: created: 2022-07-07

  • Flag to ignore main:
--defsym=main=0x100
  • To ignore _start:
-nostartfiles

RelocID Pass

  • *howto:
{type = 224, size = 2, bitsize = 32, rightshift = 1, bitpos = 0, complain_on_overflow = complain_overflow_unsigned, negate = 0, pc_relative = 1, partial_inplace = 0, pcrel_offset = 1, src_mask = 0, dst_mask = 4293918720, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7506 "R_RISCV_CVPCREL_UI12"}
  • *rel:
{r_offset = 2, r_info = 1504, r_addend = 0}
  • value: 3145728

We first do CVPCREL with the *howto:

{type = 224, size = 2, bitsize = 32, rightshift = 1, bitpos = 0, complain_on_overflow = complain_overflow_unsigned, negate = 0, pc_relative = 1, partial_inplace = 0, pcrel_offset = 1, src_mask = 0, dst_mask = 4293918720, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7506 "R_RISCV_CVPCREL_UI12"}

Value is set to 6.

Then we get to RELOCID:

{type = 59, size = 3, bitsize = 32, rightshift = 0, bitpos = 0, complain_on_overflow = complain_overflow_dont, negate = 0, pc_relative = 0, partial_inplace = 0, pcrel_offset = 0, src_mask = 0, dst_mask = 0, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7530 "R_RISCV_RELOCID"}

value += rel->r_addend therefore 100 (the ID).

We get the previous relocation:

int prev_reloc = ELFNN_R_TYPE ((rel - 1))->r_info);

The howto turns into:

{type = 224, size = 2, bitsize = 32, rightshift = 1, bitpos = 0, complain_on_overflow = complain_overflow_unsigned, negate = 0, pc_relative = 1, partial_inplace = 0, pcrel_offset = 1, src_mask = 0, dst_mask = 4293918720, special_function = 0x5555555cb8e0 <bfd_elf_generic_reloc>, name = 0x5555556c7506 "R_RISCV_CVPCREL_UI12"}

And word is 3145851.

rel however, still points to RELOCID and not CVPCREL. I don’t seem able to change the value (or addend) without accessing the actual relocation.

We go to riscv_elf_rtype_to_howto which looks for relocation 224 in the howto table and returns its location (&howto_table[i]).

When we get to r_type = 58, it jumps to 224. Therefore, it replaces RELOCID with CVPCREL in the howto table (RELOCID points to CVPCREL).

The address being returned is:

(const reloc_howto_type *) 0x5555559043b8 <howto_table+2360>

We are then sent to elfnn-riscv.c:1765 aka the default of perform_relocation: return bfd_reloc_notsupported.

If I use the riscv_reloc_type_lookup function, then prev_reloc somehow points to BFD_RELOC_MICROMIPS_GPREL16. It seems to only get

HOWTO

The howto field can be imagined as a relocation instruction. It is a pointer to a structure which contains information on what to do with all of the other information in the relocation record and data section. A back end would normally have a relocation instruction set and turn relocations into pointers to the correct structure on input - but it would be possible to create each howto field on demand.