[PATCH 1/3] RISC-V: Add ZCMT table jump relaxation
Bigmagic
zhaofujin@nucleisys.com
Mon Jun 22 02:23:53 GMT 2026
--- a/bfd/elfnn-riscv.c+++ b/bfd/elfnn-riscv.c
@@ -1893,11 +1893,18 @@ riscv_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
if (s->output_section == NULL)
return false;
- if (!_bfd_generic_link_add_one_symbol (
- info, output_bfd, RISCV_TABLE_JUMP_BASE_SYMBOL, BSF_GLOBAL, s,
- (bfd_vma) 0, (const char *) NULL, true,
- get_elf_backend_data (output_bfd)->collect, &bh))
- return false;
+ /* Only create the symbol if it doesn't already exist (e.g. from
+ a linker script PROVIDE). */
+ bh = bfd_link_hash_lookup (info->hash, RISCV_TABLE_JUMP_BASE_SYMBOL,
+ false, false, false);
+ if (bh == NULL)
+ {
+ if (!_bfd_generic_link_add_one_symbol (
+ info, output_bfd, RISCV_TABLE_JUMP_BASE_SYMBOL, BSF_GLOBAL, s,
+ (bfd_vma) 0, (const char *) NULL, true,
+ get_elf_backend_data (output_bfd)->collect, &bh))
+ return false;
+ }
}
This patch fixes an issue where the RISC-V linker would unconditionally create the __riscv_table_jump_base symbol during ZCMT relaxation, even if it was already defined in a linker script via PROVIDE.
Currently, riscv_elf_late_size_sections() always calls _bfd_generic_link_add_one_symbol() to create the __riscv_table_jump_base symbol. This overwrites any definition provided by a linker script, making it impossible for users to override this symbol with a custom address through PROVIDE.
The patch first looks up the symbol in the linker hash table using bfd_link_hash_lookup(). Only if the symbol is not found does it proceed to create it. This allows linker scripts to pre-define the symbol via PROVIDE, which will then be used by ZCMT relaxation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20260622/07f02bfe/attachment-0001.htm>
More information about the Binutils
mailing list