]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: use host CPU features in JIT disassembler
authorVarun R Mallya <varunrmallya@gmail.com>
Tue, 2 Jun 2026 20:58:46 +0000 (02:28 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 5 Jun 2026 22:26:18 +0000 (15:26 -0700)
Pass the host CPU name and feature string to
LLVMCreateDisasmCPUFeatures() instead of using LLVMCreateDisasm(), so
the disassembler correctly decodes CPU-specific instructions and
extensions such as RISC-V compressed and vector instructions.

Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Link: https://lore.kernel.org/r/20260602205847.102825-2-varunrmallya@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/jit_disasm_helpers.c

index 364c557c51158dc36acd901e489f40c297aa7b94..3558fe10e28cf96f06d65736346d0a1655243919 100644 (file)
@@ -96,10 +96,19 @@ static int disasm_one_func(FILE *text_out, uint8_t *image, __u32 len)
        __u32 *label_pc, pc;
        int i, cnt, err = 0;
        char buf[64];
+       char *cpu, *features;
 
        triple = LLVMGetDefaultTargetTriple();
-       ctx = LLVMCreateDisasm(triple, &labels, 0, NULL, lookup_symbol);
-       if (!ASSERT_OK_PTR(ctx, "LLVMCreateDisasm")) {
+
+       cpu = LLVMGetHostCPUName();
+       features = LLVMGetHostCPUFeatures();
+
+       ctx = LLVMCreateDisasmCPUFeatures(triple, cpu, features, &labels, 0, NULL, lookup_symbol);
+
+       LLVMDisposeMessage(cpu);
+       LLVMDisposeMessage(features);
+
+       if (!ASSERT_OK_PTR(ctx, "LLVMCreateDisasmCPUFeatures")) {
                err = -EINVAL;
                goto out;
        }