bpftool: Support setting alternative arch for JIT disasm with LLVM

For offloaded BPF programs, instead of failing to create the
LLVM disassembler without even looking for a triple at all, do run the
function that attempts to retrieve a valid architecture name for the
device.

It will still fail for the LLVM disassembler, because currently we have
no valid triple to return (NFP disassembly is not supported by LLVM).
But failing in that function is more logical than to assume in
jit_disasm.c that passing an "arch" name is simply not supported.

Suggested-by: Song Liu <song@kernel.org>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/r/20221025150329.97371-8-quentin@isovalent.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Quentin Monnet
2022-10-25 16:03:28 +01:00
committed by Alexei Starovoitov
parent eb9d1acf63
commit ce4f660862
4 changed files with 16 additions and 18 deletions

View File

@@ -84,12 +84,10 @@ init_context(disasm_ctx_t *ctx, const char *arch,
{
char *triple;
if (arch) {
p_err("Architecture %s not supported", arch);
return -1;
}
triple = LLVMGetDefaultTargetTriple();
if (arch)
triple = LLVMNormalizeTargetTriple(arch);
else
triple = LLVMGetDefaultTargetTriple();
if (!triple) {
p_err("Failed to retrieve triple");
return -1;
@@ -128,8 +126,9 @@ disassemble_insn(disasm_ctx_t *ctx, unsigned char *image, ssize_t len, int pc)
int disasm_init(void)
{
LLVMInitializeNativeTarget();
LLVMInitializeNativeDisassembler();
LLVMInitializeAllTargetInfos();
LLVMInitializeAllTargetMCs();
LLVMInitializeAllDisassemblers();
return 0;
}
#endif /* HAVE_LLVM_SUPPORT */