[PATCH 0/2] RISC-V: Check for conflicting extensions when the linker merges arch attributes

Ethan Y. C. Liang ycl669@andestech.com
Mon Jul 6 11:44:26 GMT 2026


This is a rework of
"[PATCH v2] RISC-V: Check if the merged ISA string is conflicting"
(https://sourceware.org/pipermail/binutils/2025-December/146173.html).

When the linker merges Tag_RISCV_arch attributes, the arch of each
input is validated on its own when parsed, but the merged arch is
never checked as a whole, so conflicting extensions could silently
slip through:

  $ as -mabi=ilp32 -march=rv32ic a.s -o a.o          # valid on its own
  $ as -mabi=ilp32 -march=rv32id_zcmp b.s -o b.o     # valid on its own
  $ ld -r -m elf32lriscv a.o b.o -o ab.o             # silently succeeds

The link succeeds even though `c' from a.o and `d' from b.o imply
`zcd', which conflicts with `zcmp'.  The same combination is rejected
by gas (-march=rv32icd_zcmp).

Patch 1 is preparatory: riscv_merge_arch_attr_info leaked the subset
lists on its error paths, and the new error path added by patch 2
would make this worse, so route all error paths through a single
cleanup exit first.

Patch 2 adds the check: after merging the input archs, re-derive the
implicit extensions on the merged arch and run the conflict checks on
it, rejecting the merge if any conflict is found.  It also adds tests
for such merges, including the case above.

Ethan Y. C. Liang (2):
  RISC-V: Release subset lists on all paths when the linker merges arch
    attributes
  RISC-V: Check for conflicting extensions when the linker merges arch
    attributes

 bfd/elfxx-riscv.c                             | 29 ++++++++++++-------
 .../ld-riscv-elf/attr-merge-arch-failed-01.d  |  5 ++++
 .../ld-riscv-elf/attr-merge-arch-failed-01.l  |  2 ++
 .../ld-riscv-elf/attr-merge-arch-failed-01a.s |  1 +
 .../ld-riscv-elf/attr-merge-arch-failed-01b.s |  1 +
 .../ld-riscv-elf/attr-merge-arch-failed-02.d  |  5 ++++
 .../ld-riscv-elf/attr-merge-arch-failed-02.l  |  2 ++
 .../ld-riscv-elf/attr-merge-arch-failed-02a.s |  1 +
 .../ld-riscv-elf/attr-merge-arch-failed-02b.s |  1 +
 .../ld-riscv-elf/attr-merge-arch-failed-03.d  |  5 ++++
 .../ld-riscv-elf/attr-merge-arch-failed-03.l  |  2 ++
 .../ld-riscv-elf/attr-merge-arch-failed-03a.s |  1 +
 .../ld-riscv-elf/attr-merge-arch-failed-03b.s |  1 +
 .../ld-riscv-elf/attr-merge-arch-failed-04.d  |  5 ++++
 .../ld-riscv-elf/attr-merge-arch-failed-04.l  |  2 ++
 .../ld-riscv-elf/attr-merge-arch-failed-04a.s |  1 +
 .../ld-riscv-elf/attr-merge-arch-failed-04b.s |  1 +
 ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp    |  4 +++
 18 files changed, 59 insertions(+), 10 deletions(-)
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-01.l
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-01a.s
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-01b.s
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02.l
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-03.d
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-03.l
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-03a.s
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-03b.s
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-04.d
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-04.l
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-04a.s
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-04b.s

-- 
2.54.0



More information about the Binutils mailing list