[PING][PATCH v2] RISC-V: Check if the merged ISA string is conflicting

Kito Cheng kito.cheng@sifive.com
Thu Apr 16 08:15:32 GMT 2026


LGTM, this change seems right to me.

On Thu, Apr 16, 2026 at 3:43 PM Ethan Y. C. Liang <ycl669@andestech.com>
wrote:

> Hi Nelson,
>
> Just a quick ping on the patch.
> Let me know if you need anything from my side.
>
> Thanks,
> Ethan
>
>
> On Fri, Dec 05, 2025 at 10:17:27AM +0800, Yu-Cheng Liang wrote:
> > Previously, when merging the arch attributes from input BFDs, the
> > linker did not verify whether the merged ISA string was conflicting.
> > This patch parses the merged ISA string and reports an error if it
> > contains conflicting extensions. New tests are added to ensure that
> > ISA-conflict cases are correctly rejected.
> >
> > Signed-off-by: Yu-Cheng Liang <yclwlcy@gmail.com>
> > ---
> >  bfd/elfnn-riscv.c                                    | 8 ++++++++
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.d  | 5 +++++
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.l  | 2 ++
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01a.s | 1 +
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01b.s | 1 +
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.d  | 5 +++++
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.l  | 2 ++
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02a.s | 1 +
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02b.s | 1 +
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.d  | 5 +++++
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.l  | 2 ++
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03a.s | 1 +
> >  ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03b.s | 1 +
> >  ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp           | 3 +++
> >  14 files changed, 38 insertions(+)
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.d
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.l
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01a.s
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01b.s
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.d
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.l
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02a.s
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02b.s
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.d
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.l
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03a.s
> >  create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03b.s
> >
> > diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
> > index 345b3bb96fd..b517b71135d 100644
> > --- a/bfd/elfnn-riscv.c
> > +++ b/bfd/elfnn-riscv.c
> > @@ -4205,6 +4205,14 @@ riscv_merge_arch_attr_info (bfd *ibfd, char
> > *in_arch, char *out_arch)
> >    merged_arch_str = riscv_arch_str (ARCH_SIZE, &merged_subsets,
> >       false/* update */);
> >
> > +  /* 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);
> >    riscv_release_subset_list (&out_subsets);
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.d
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.d
> > new file mode 100644
> > index 00000000000..af3f5ad0a47
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.d
> > @@ -0,0 +1,5 @@
> > +#source: attr-merge-arch-fail-01a.s
> > +#source: attr-merge-arch-fail-01b.s
> > +#as:
> > +#ld: -r -m[riscv_choose_ilp32_emul]
> > +#error_output: attr-merge-arch-fail-01.l
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.l
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.l
> > new file mode 100644
> > index 00000000000..67393a43943
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01.l
> > @@ -0,0 +1,2 @@
> > +.*: `zfinx' is conflict with the `f/d/q/zfh/zfhmin' extension
> > +.*: failed to merge target specific data of file .*
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01a.s
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01a.s
> > new file mode 100644
> > index 00000000000..8f2a98f95f3
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01a.s
> > @@ -0,0 +1 @@
> > + .attribute arch, "rv32i_zfinx"
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01b.s
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01b.s
> > new file mode 100644
> > index 00000000000..a44b2a0d346
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-01b.s
> > @@ -0,0 +1 @@
> > + .attribute arch, "rv32if"
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.d
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.d
> > new file mode 100644
> > index 00000000000..0ea2a31ba80
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.d
> > @@ -0,0 +1,5 @@
> > +#source: attr-merge-arch-fail-02a.s
> > +#source: attr-merge-arch-fail-02b.s
> > +#as:
> > +#ld: -r -m[riscv_choose_ilp32_emul]
> > +#error_output: attr-merge-arch-fail-02.l
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.l
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.l
> > new file mode 100644
> > index 00000000000..930e03123e1
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02.l
> > @@ -0,0 +1,2 @@
> > +.*: zcmp' is incompatible with `d' and `c', or `zcd' extension
> > +.*: failed to merge target specific data of file .*
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02a.s
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02a.s
> > new file mode 100644
> > index 00000000000..3f79059d5d0
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02a.s
> > @@ -0,0 +1 @@
> > + .attribute arch, "rv32i_zcmp"
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02b.s
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02b.s
> > new file mode 100644
> > index 00000000000..95bfe1f6d9f
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-02b.s
> > @@ -0,0 +1 @@
> > + .attribute arch, "rv32i_zcd"
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.d
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.d
> > new file mode 100644
> > index 00000000000..43c646d4d8c
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.d
> > @@ -0,0 +1,5 @@
> > +#source: attr-merge-arch-fail-03a.s
> > +#source: attr-merge-arch-fail-03b.s
> > +#as:
> > +#ld: -r -m[riscv_choose_ilp32_emul]
> > +#error_output: attr-merge-arch-fail-03.l
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.l
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.l
> > new file mode 100644
> > index 00000000000..28345aa930d
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03.l
> > @@ -0,0 +1,2 @@
> > +.*: `zclsd' is conflict with the `c\+f'/ `zcf' extension
> > +.*: failed to merge target specific data of file .*
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03a.s
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03a.s
> > new file mode 100644
> > index 00000000000..f7f9ceb11f6
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03a.s
> > @@ -0,0 +1 @@
> > + .attribute arch, "rv32i_zclsd"
> > diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03b.s
> > b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03b.s
> > new file mode 100644
> > index 00000000000..f18129dc55d
> > --- /dev/null
> > +++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-fail-03b.s
> > @@ -0,0 +1 @@
> > + .attribute arch, "rv32i_zcf"
> > diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> > b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> > index b0d510ac8da..3a47a260d7d 100644
> > --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> > +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> > @@ -154,6 +154,9 @@ if [istarget "riscv*-*-*"] {
> >      run_dump_test "attr-merge-arch-01"
> >      run_dump_test "attr-merge-arch-02"
> >      run_dump_test "attr-merge-arch-03"
> > +    run_dump_test "attr-merge-arch-fail-01"
> > +    run_dump_test "attr-merge-arch-fail-02"
> > +    run_dump_test "attr-merge-arch-fail-03"
> >      run_dump_test "attr-merge-strict-align-01"
> >      run_dump_test "attr-merge-strict-align-02"
> >      run_dump_test "attr-merge-strict-align-03"
> > --
> > 2.49.0
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20260416/b30fc043/attachment-0001.htm>


More information about the Binutils mailing list