Skip to content

Commit

Permalink
RISC-V: Implment Tag_RISCV_x3_reg_usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kito-cheng committed Aug 18, 2023
1 parent 3020782 commit d13849c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions bfd/elfnn-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4024,6 +4024,21 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
}
}
break;

case Tag_RISCV_x3_reg_usage:
if (in_attr[i].i > 3)
_bfd_error_handler
(_("error: %pB use unknown value (%d) for Tag_RISCV_x3_reg_usage."),
ibfd, in_attr[i].i);
if (out_attr[i].i == 0 && in_attr[i].i != 3)
out_attr[i].i = in_attr[i].i;
if (in_attr[i].i != out_attr[i].i)
_bfd_error_handler
(_("error: %pB has incompatible value %d "
"with output %pB (%d) for Tag_RISCV_x3_reg_usage."),
ibfd, in_attr[i].i, obfd, out_attr[i].i);
break;

default:
result &= _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
}
Expand Down
24 changes: 24 additions & 0 deletions binutils/readelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -18330,6 +18330,7 @@ static struct riscv_attr_tag_t riscv_attr_tag[] =
T(unaligned_access),
T(stack_align),
T(atomic_abi),
T(x3_reg_usage),
#undef T
};

Expand Down Expand Up @@ -18404,6 +18405,29 @@ display_riscv_attribute (unsigned char *p,
break;
}
break;
case Tag_RISCV_x3_reg_usage:
READ_ULEB (val, p, end);
printf ("%" PRIu64, val);
switch (val)
{
case 0:
printf (_("(UNKNOWN)\n"));
break;
case 1:
printf (_("('x3' as the global pointer, for relaxation purposes.)\n"));
break;
case 2:
printf (_("('x3' as the shadow stack pointer.)\n"));
break;
case 4:
printf (_("('x3' as a temporary register.)\n"));
break;
default:
printf (_("%" PRIu64 " (Unrecognized `x3` usage)\n"), val);
break;
}
break;

case Tag_RISCV_arch:
p = display_tag_value (-1, p, end);
break;
Expand Down
1 change: 1 addition & 0 deletions gas/config/tc-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5246,6 +5246,7 @@ riscv_convert_symbolic_attribute (const char *name)
T(unaligned_access),
T(stack_align),
T(atomic_abi),
T(x3_reg_usage),
#undef T
};

Expand Down
3 changes: 2 additions & 1 deletion include/elf/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ enum
Tag_RISCV_priv_spec = 8,
Tag_RISCV_priv_spec_minor = 10,
Tag_RISCV_priv_spec_revision = 12,
Tag_RISCV_atomic_abi = 14
Tag_RISCV_atomic_abi = 14,
Tag_RISCV_x3_reg_usage = 16
};

#endif /* _ELF_RISCV_H */

0 comments on commit d13849c

Please sign in to comment.