RISC-V: Check if the merged ISA string is conflicting

Message ID CALWc1WCqpTRM_tq8uT94AV9FGGg=5SHHaDfL0cyyg3XXCGu5wQ@mail.gmail.com
State New
Headers
Series RISC-V: Check if the merged ISA string is conflicting |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply

Commit Message

Yu-Cheng Liang Jan. 13, 2025, 6:29 a.m. UTC
  In the current implementation, the linker does not check if the merged
ISA string is conflicting when attempting to merge two ISA strings.
For instance, no error message is generated when the linker links
objectA (rv64i_zfinx) with objectB (rv64if).

Signed-off-by: Yu-Cheng Liang <yclwlcy@gmail.com>
---
 bfd/elfnn-riscv.c | 8 ++++++++
 1 file changed, 8 insertions(+)

   riscv_release_subset_list (&out_subsets);
--
2.47.1
  

Patch

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 3aba9c85b0f..0b8c7c33117 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -3965,6 +3965,14 @@  riscv_merge_arch_attr_info (bfd *ibfd, char
*in_arch, char *out_arch)

   merged_arch_str = riscv_arch_str (ARCH_SIZE, &merged_subsets);

+  /* Check if the merged ISA string is conflicting.  */
+  riscv_subset_list_t subsets = {NULL, NULL, NULL};
+  unsigned xlen;
+  riscv_parse_subset_t riscv_rps_merged =
+    {&subsets, _bfd_error_handler, &xlen, NULL, false};
+  if (!riscv_parse_subset (&riscv_rps_merged, merged_arch_str))
+    return NULL;
+
   /* Release the subset lists.  */
   riscv_release_subset_list (&in_subsets);