You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After ratification of the RISC-V psABI specification (version 1.0), it
is getting enhanced and improved.
This commit performs following changes.
1. Reject unknown ELF relocation types when fed into a tool
Before this commit, it accepted unknown (but small) relocation types and
relocation types only for internal uses (linker relaxation). More
worryingly, some internal only relocation types conflict with global
relocation types in the latest psABI draft [1].
[1] <riscv-non-isa/riscv-elf-psabi-doc@d49e480>
If (a) psABI changes conflict with internal only relocation types and/or
(b) an object (possibly malicious or just from the future) with unknown
relocation type is encountered while linking (by ld) or relocating by
other tools, it can cause a severe failure (with
unpredictable erroneous results).
This commit now rejects small unknown relocation types and internal only
ones when an ELF file with such relocation types is fed into a tool.
2. Move internal only ELF relocation types after all regular ones
Currently, we have six internal only relocation types but only
R_RISCV_DELETE is distinguished from the regular one (others were defined
in between regular relocation types). This design caused the conflict
with regular relocation types *and* made fixing the number of such
internal relocation a non-trivial task.
This commit moves all internal only relocation types (not only
R_RISCV_DELETE) after R_RISCV_max and creates separate howto relocation
table for range (R_RISCV_DELETE + 1..R_RISCV_internal_max).
All internal only relocations are defined relative to R_RISCV_max and
will not conflict with regular ones (if psABI started to use large numbers,
internal relocations are automatically adjusted).
3. Prevent internal only ELF relocation types from emitting
It prevents emitting internal only relocations when the --emit-relocs
option is specified when linking (instead, replaces such internal only
relocations to R_RISCV_NONE).
bfd/ChangeLog:
* elfnn-riscv.c (R_RISCV_DELETE): Move to elf_riscv_reloc_type.
(riscv_info_to_howto_rela, bad_static_reloc): Reflect
riscv_elf_rtype_to_howto changes.
(riscv_elf_check_relocs): Likewise. Also reject unknown relocs
are found. Reuse howto variable.
(riscv_elf_relocate_section): Reflect riscv_elf_rtype_to_howto
changesL but also look up for internal relocs only when necessary.
Delete internal only relocation after the relocation.
* elfxx-riscv.c (HOWTO_ISEMPTY): New macro to query whether the
howto entry is empty.
(howto_table): Reserve all howto entries defined by the latest
RISC-V psABI specification except no actual EMPTY_HOWTO defs
at the end of the list. Move internal only relocs to...
(howto_table_internal): ...here.
(riscv_elf_rtype_to_howto): Add ability to look up internal only
relocation types only when necessary.
* elfxx-riscv.h (riscv_elf_rtype_to_howto): Reflect above.
include/ChangeLog:
* elf/riscv.h (enum elf_riscv_reloc_type): Comment all reserved
relocation types as defined by the latest RISC-V psABI spec.
Move all internal relocation types after R_RISCV_max, first being
R_RISCV_DELETE. Add R_RISCV_internal_max. Add safety guard for
all relocation types on C11 and later.
0 commit comments