[PATCH] ld: RISC-V: Select the matching emulation for Zcmt tests

Kito Cheng kito.cheng@gmail.com
Thu Nov 26 08:39:00 GMT 2026


LGTM

Jiawei <jiawei@iscas.ac.cn> 於 2026年11月26日週四 下午1:27寫道:
>
> Most table-jump tests assemble RV64 objects.  On riscv32-elf the
> linker defaults to ELF32 and rejects those objects before the tests
> reach the relaxation or inspect the jump table.
>
> Select LP64 for this group and use the target byte order for the
> cases that specify their own XLEN.  Keep the explicit little- and
> big-endian tests in their respective emulations.
>
> Use objdump -z in tests that inspect sparse RV64 jump tables.  On a
> big-endian target, skipping zero bytes can resume halfway through an
> eight-byte entry.  Check the empty slots around the gap as well as
> the targets in slots 0 and 32.
>
> Reported-by: Alan Modra <amodra@gmail.com>
> Link: https://sourceware.org/pipermail/binutils/2026-November/152915.html
>
> ld/ChangeLog:
>
>         * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Use LP64 as the default
>         emulation for the Zcmt tests.
>         * testsuite/ld-riscv-elf/table-jump-address-edge-default.d: Select
>         LP64 for the target byte order.
>         * testsuite/ld-riscv-elf/table-jump-address-edge.d: Ditto.
>         * testsuite/ld-riscv-elf/table-jump-page-jal.d: Ditto.
>         * testsuite/ld-riscv-elf/table-jump-page.d: Ditto.
>         * testsuite/ld-riscv-elf/table-jump-relax-tbljal.d: Disassemble the
>         zero JVT entries and check the gap between slots 0 and 32.
>         * testsuite/ld-riscv-elf/table-jump-rv32.d: Select ILP32 for the
>         target byte order.
>         * testsuite/ld-riscv-elf/table-jump-tbljal-options.d: Disassemble
>         zero entries for the option variants that inspect the JVT.
>         * testsuite/ld-riscv-elf/table-jump-tbljal-zcmt-rv32.d: Select ILP32
>         for the target byte order.
>         * testsuite/ld-riscv-elf/table-jump-vma-lma.d: Disassemble zero
>         entries.
>         * testsuite/ld-riscv-elf/table-jump-weak-base-rv32-no-table.d:
>         Select ILP32 for the target byte order.
>         * testsuite/ld-riscv-elf/table-jump-weak-base-rv32.d: Ditto.
> ---
>  ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp                 | 7 ++++++-
>  .../ld-riscv-elf/table-jump-address-edge-default.d         | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-address-edge.d        | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-page-jal.d            | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-page.d                | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-relax-tbljal.d        | 6 ++++--
>  ld/testsuite/ld-riscv-elf/table-jump-rv32.d                | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-tbljal-options.d      | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-tbljal-zcmt-rv32.d    | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-vma-lma.d             | 2 +-
>  .../ld-riscv-elf/table-jump-weak-base-rv32-no-table.d      | 2 +-
>  ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32.d      | 2 +-
>  12 files changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> index 0adee8006e5..786439f4598 100644
> --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> @@ -242,7 +242,10 @@ if [istarget "riscv*-*-*"] {
>             "-march=rv64i -mabi=lp64" {weakref64.s} \
>             {{objdump -d weakref64.d}} "weakref64"]]
>
> -    # Zcmt (jump table) tests.
> +    # Most Zcmt tests assemble RV64 inputs.  The RV32 and explicit-endian
> +    # tests select their own emulation in their .d files.
> +    set saved_ldflags $LDFLAGS
> +    append LDFLAGS " -m[riscv_choose_lp64_emul]"
>      run_dump_test "table-jump-jalt"
>      run_dump_test "table-jump-jt"
>      run_dump_test "table-jump-dump-unknown"
> @@ -353,6 +356,7 @@ if [istarget "riscv*-*-*"] {
>
>      # The following tests require shared library support.
>      if ![check_shared_lib_support] {
> +       set LDFLAGS $saved_ldflags
>         return
>      }
>
> @@ -363,6 +367,7 @@ if [istarget "riscv*-*-*"] {
>      run_dump_test "table-jump-shared-text"
>      run_dump_test "table-jump-shared-symbol"
>      run_dump_test "table-jump-shared-relocs"
> +    set LDFLAGS $saved_ldflags
>
>      run_dump_test "relro-relax-lui"
>      run_dump_test "relro-relax-pcrel"
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-address-edge-default.d b/ld/testsuite/ld-riscv-elf/table-jump-address-edge-default.d
> index 075e727831f..89b615bf385 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-address-edge-default.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-address-edge-default.d
> @@ -1,6 +1,6 @@
>  #source: table-jump-address-edge.s
>  #as: -march=rv64ic_zcmt -mabi=lp64
> -#ld: -melf64lriscv --no-warn-rwx-segments -Ttable-jump-address-edge.ld
> +#ld: -m[riscv_choose_lp64_emul] --no-warn-rwx-segments -Ttable-jump-address-edge.ld
>  #objdump: -d -M no-aliases -j .text
>
>  #...
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-address-edge.d b/ld/testsuite/ld-riscv-elf/table-jump-address-edge.d
> index 884247885f0..33ed6f7ffb7 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-address-edge.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-address-edge.d
> @@ -1,6 +1,6 @@
>  #source: table-jump-address-edge.s
>  #as: -march=rv64ic_zcmt -mabi=lp64
> -#ld: -melf64lriscv --no-warn-rwx-segments -Ttable-jump-address-edge.ld --relax-tbljal
> +#ld: -m[riscv_choose_lp64_emul] --no-warn-rwx-segments -Ttable-jump-address-edge.ld --relax-tbljal
>  #objdump: -d -M no-aliases -j .text -j .riscv.jvt
>
>  #...
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-page-jal.d b/ld/testsuite/ld-riscv-elf/table-jump-page-jal.d
> index bf41428ab04..7e544e5b7ff 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-page-jal.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-page-jal.d
> @@ -1,6 +1,6 @@
>  #source: table-jump-page.s
>  #as: -march=rv64ic_zcmt -mabi=lp64 --defsym TEST_JAL=1
> -#ld: -melf64lriscv --no-warn-rwx-segments --defsym=page_size=0x200000 -Ttable-jump-page.ld --relax-tbljal
> +#ld: -m[riscv_choose_lp64_emul] --no-warn-rwx-segments --defsym=page_size=0x200000 -Ttable-jump-page.ld --relax-tbljal
>  #objdump: -d -M no-aliases -j .text -j .fillers
>
>  #...
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-page.d b/ld/testsuite/ld-riscv-elf/table-jump-page.d
> index cba9bca5925..d5e95f08363 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-page.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-page.d
> @@ -1,6 +1,6 @@
>  #source: table-jump-page.s
>  #as: -march=rv64ic_zcmt -mabi=lp64
> -#ld: -melf64lriscv --no-warn-rwx-segments --defsym=page_size=0x1000 -Ttable-jump-page.ld --relax-tbljal
> +#ld: -m[riscv_choose_lp64_emul] --no-warn-rwx-segments --defsym=page_size=0x1000 -Ttable-jump-page.ld --relax-tbljal
>  #objdump: -d -M no-aliases -j .text -j .fillers
>
>  #...
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-relax-tbljal.d b/ld/testsuite/ld-riscv-elf/table-jump-relax-tbljal.d
> index 831fb5b4f6f..2c9d81d5eb1 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-relax-tbljal.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-relax-tbljal.d
> @@ -1,12 +1,14 @@
>  #source: table-jump.s
>  #as: -march=rv64ic_zcmt --defsym TEST_CM_JT_JALT=1
>  #ld: -Ttable-jump.ld --relax-tbljal
> -#objdump: -d
> +#objdump: -dz
>  #...
>  Disassembly of section .riscv.jvt:
>  0+[0-9a-f]+ <__jvt_base\$>:
>  .*:[   ]+[0-9a-f]+[    ]+jvt.jt\[0\]:[         ]+foo_global
> -[      ]+...
> +.*:[   ]+0000000000000000[     ]+jvt.jt\[1\]:.*
> +#...
> +.*:[   ]+0000000000000000[     ]+jvt.jt\[31\]:.*
>  .*:[   ]+[0-9a-f]+[    ]+jvt.jalt\[32\]:[      ]+foo_global
>  #...
>  Disassembly of section .text:
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-rv32.d b/ld/testsuite/ld-riscv-elf/table-jump-rv32.d
> index 26dc99cde5f..80fa924d9bc 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-rv32.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-rv32.d
> @@ -1,6 +1,6 @@
>  #source: table-jump-rv32.s
>  #as: -march=rv32ic_zcmt
> -#ld: -Ttable-jump.ld --relax-tbljal -melf32lriscv
> +#ld: -Ttable-jump.ld --relax-tbljal -m[riscv_choose_ilp32_emul]
>  #objdump: -d
>  #...
>  Disassembly of section .riscv.jvt:
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-tbljal-options.d b/ld/testsuite/ld-riscv-elf/table-jump-tbljal-options.d
> index e12434c174d..d81706f710a 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-tbljal-options.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-tbljal-options.d
> @@ -1,7 +1,7 @@
>  #source: table-jump.s
>  #as: -march=rv64ic_zcmt --defsym TEST_CM_JT_JALT=1
>  #ld: -Ttable-jump.ld
> -#objdump: -d
> +#objdump: -dz
>  #...
>  Disassembly of section .text:
>  0+[0-9a-f]+ <_start>:
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-tbljal-zcmt-rv32.d b/ld/testsuite/ld-riscv-elf/table-jump-tbljal-zcmt-rv32.d
> index 79d5f7f4747..02c0d211547 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-tbljal-zcmt-rv32.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-tbljal-zcmt-rv32.d
> @@ -1,5 +1,5 @@
>  #source: table-jump-rv32.s
>  #as: -march=rv32ic_zcmt
> -#ld: -Ttable-jump.ld --relax-tbljal=zcmt -melf32lriscv
> +#ld: -Ttable-jump.ld --relax-tbljal=zcmt -m[riscv_choose_ilp32_emul]
>  #objdump: -d
>  #dump: table-jump-rv32.d
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-vma-lma.d b/ld/testsuite/ld-riscv-elf/table-jump-vma-lma.d
> index 03fdcce4399..483e6adb4a2 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-vma-lma.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-vma-lma.d
> @@ -1,7 +1,7 @@
>  #source: table-jump.s
>  #as: -march=rv64ic_zcmt --defsym TEST_CM_JALT=1
>  #ld: -Ttable-jump-vma-lma.ld --relax-tbljal
> -#objdump: -d
> +#objdump: -dz
>
>  #...
>  Disassembly of section .riscv.jvt:
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32-no-table.d b/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32-no-table.d
> index ad634e145f5..00cd574b903 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32-no-table.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32-no-table.d
> @@ -1,6 +1,6 @@
>  #source: table-jump-weak-base.s
>  #as: -march=rv32ic_zcmt -mabi=ilp32 --defsym SITES=1
> -#ld: -melf32lriscv -Ttable-jump-weak-base.ld --relax-tbljal
> +#ld: -m[riscv_choose_ilp32_emul] -Ttable-jump-weak-base.ld --relax-tbljal
>  #objdump: -d
>
>  #...
> diff --git a/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32.d b/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32.d
> index 594b605daba..5ee074628f2 100644
> --- a/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32.d
> +++ b/ld/testsuite/ld-riscv-elf/table-jump-weak-base-rv32.d
> @@ -1,6 +1,6 @@
>  #source: table-jump-weak-base.s
>  #as: -march=rv32ic_zcmt -mabi=ilp32 --defsym SITES=3
> -#ld: -melf32lriscv -Ttable-jump-weak-base.ld --relax-tbljal
> +#ld: -m[riscv_choose_ilp32_emul] -Ttable-jump-weak-base.ld --relax-tbljal
>  #objdump: -d
>
>  #...
>
> base-commit: d2d454debdb2ba87435f032bae3b65ceb544dfcb
>


More information about the Binutils mailing list