Dmitry Safonov
fd4eeb30b9
objtool: Print bfd_vma as unsigned long long on ia32-x86_64 cross build
...
When objtool is cross-compiled in ia32 container for x86_64 target it
fails with the following errors:
> disas.c: In function 'disas_print_addr_sym':
> disas.c:173:38: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'bfd_vma' {aka 'long long unsigned int'} [-Werror=format=]
> 173 | DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
> | ^~~~~~~~~~~~ ~~~~
> | |
> | bfd_vma {aka long long unsigned int}
Provide a correct printf-fmt depending on sizeof(bfd_vma).
Fixes: 5d859dff26 ("objtool: Print symbol during disassembly")
Signed-off-by: Dmitry Safonov <dima@arista.com >
Reviewed-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Link: https://patch.msgid.link/20260126-objtool-ia32-v1-1-bb6feaf17566@arista.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org >
2026-01-27 08:19:35 -08:00
Ingo Molnar
6ec33db1aa
objtool: Fix segfault on unknown alternatives
...
So 'objtool --link -d vmlinux.o' gets surprised by this endbr64+endbr64 pattern
in ___bpf_prog_run():
___bpf_prog_run:
1e7680: ___bpf_prog_run+0x0 push %r12
1e7682: ___bpf_prog_run+0x2 mov %rdi,%r12
1e7685: ___bpf_prog_run+0x5 push %rbp
1e7686: ___bpf_prog_run+0x6 xor %ebp,%ebp
1e7688: ___bpf_prog_run+0x8 push %rbx
1e7689: ___bpf_prog_run+0x9 mov %rsi,%rbx
1e768c: ___bpf_prog_run+0xc movzbl (%rbx),%esi
1e768f: ___bpf_prog_run+0xf movzbl %sil,%edx
1e7693: ___bpf_prog_run+0x13 mov %esi,%eax
1e7695: ___bpf_prog_run+0x15 mov 0x0(,%rdx,8),%rdx
1e769d: ___bpf_prog_run+0x1d jmp 0x1e76a2 <__x86_indirect_thunk_rdx>
1e76a2: ___bpf_prog_run+0x22 endbr64
1e76a6: ___bpf_prog_run+0x26 endbr64
1e76aa: ___bpf_prog_run+0x2a mov 0x4(%rbx),%edx
And crashes due to blindly dereferencing alt->insn->alt_group.
Bail out on NULL ->alt_group, which produces this warning and continues
with the disassembly, instead of a segfault:
.git/O/vmlinux.o: warning: objtool: <alternative.1e769d>: failed to disassemble alternative
Cc: Alexandre Chartre <alexandre.chartre@oracle.com >
Cc: Peter Zijlstra (Intel) <peterz@infradead.org >
Cc: Josh Poimboeuf <jpoimboe@kernel.org >
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org >
2025-12-01 10:42:27 +01:00
Alexandre Chartre
c0a67900dc
objtool: Trim trailing NOPs in alternative
...
When disassembling alternatives replace trailing NOPs with a single
indication of the number of bytes covered with NOPs.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-31-alexandre.chartre@oracle.com
2025-11-24 20:40:48 +01:00
Alexandre Chartre
aff95e0d4e
objtool: Add wide output for disassembly
...
Add the --wide option to provide a wide output when disassembling.
With this option, the disassembly of alternatives is displayed
side-by-side instead of one above the other.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-30-alexandre.chartre@oracle.com
2025-11-24 20:40:48 +01:00
Alexandre Chartre
07d70b271a
objtool: Compact output for alternatives with one instruction
...
When disassembling, if an instruction has alternatives which are all
made of a single instruction then print each alternative on a single
line (instruction + description) so that the output is more compact.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-29-alexandre.chartre@oracle.com
2025-11-24 20:40:48 +01:00
Alexandre Chartre
56967b9a77
objtool: Improve naming of group alternatives
...
Improve the naming of group alternatives by showing the feature name and
flags used by the alternative.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-28-alexandre.chartre@oracle.com
2025-11-24 20:40:48 +01:00
Alexandre Chartre
4aae0d3f77
objtool: Fix address references in alternatives
...
When using the --disas option, alternatives are disassembled but
address references in non-default alternatives can be incorrect.
The problem is that alternatives are shown as if they were replacing the
original code of the alternative. So if an alternative is referencing
an address inside the alternative then the reference has to be
adjusted to the location of the original code.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-25-alexandre.chartre@oracle.com
2025-11-21 15:30:14 +01:00
Alexandre Chartre
7e017720aa
objtool: Disassemble jump table alternatives
...
When using the --disas option, also disassemble jump tables.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-24-alexandre.chartre@oracle.com
2025-11-21 15:30:14 +01:00
Alexandre Chartre
78df4590c5
objtool: Disassemble exception table alternatives
...
When using the --disas option, also disassemble exception tables
(EX_TABLE).
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-23-alexandre.chartre@oracle.com
2025-11-21 15:30:14 +01:00
Alexandre Chartre
15e7ad8667
objtool: Print addresses with alternative instructions
...
All alternatives are disassemble side-by-side when using the --disas
option. However the address of each instruction is not printed because
instructions from different alternatives are not necessarily aligned.
Change this behavior to print the address of each instruction. Spaces
will appear between instructions from the same alternative when
instructions from different alternatives do not have the same alignment.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-22-alexandre.chartre@oracle.com
2025-11-21 15:30:13 +01:00
Alexandre Chartre
a4f1599672
objtool: Disassemble group alternatives
...
When using the --disas option, disassemble all group alternatives.
Jump tables and exception tables (which are handled as alternatives)
are not disassembled at the moment.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-21-alexandre.chartre@oracle.com
2025-11-21 15:30:13 +01:00
Alexandre Chartre
87343e6642
objtool: Print headers for alternatives
...
When using the --disas option, objtool doesn't currently disassemble
any alternative. Print an header for each alternative. This identifies
places where alternatives are present but alternative code is still
not disassembled at the moment.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-20-alexandre.chartre@oracle.com
2025-11-21 15:30:13 +01:00
Alexandre Chartre
5f326c8897
objtool: Add the --disas=<function-pattern> action
...
Add the --disas=<function-pattern> actions to disassemble the specified
functions. The function pattern can be a single function name (e.g.
--disas foo to disassemble the function with the name "foo"), or a shell
wildcard pattern (e.g. --disas foo* to disassemble all functions with a
name starting with "foo").
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-18-alexandre.chartre@oracle.com
2025-11-21 15:30:12 +01:00
Alexandre Chartre
9b580accac
objtool: Add functions to better name alternatives
...
Add the disas_alt_name() and disas_alt_type_name() to provide a
name and a type name for an alternative. This will be used to
better name alternatives when tracing their execution.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-15-alexandre.chartre@oracle.com
2025-11-21 15:30:11 +01:00
Alexandre Chartre
70589843b3
objtool: Add option to trace function validation
...
Add an option to trace and have information during the validation
of specified functions. Functions are specified with the --trace
option which can be a single function name (e.g. --trace foo to
trace the function with the name "foo"), or a shell wildcard
pattern (e.g. --trace foo* to trace all functions with a name
starting with "foo").
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-11-alexandre.chartre@oracle.com
2025-11-21 15:30:09 +01:00
Alexandre Chartre
0bb080ba64
objtool: Disassemble instruction on warning or backtrace
...
When an instruction warning (WARN_INSN) or backtrace (BT_INSN) is issued,
disassemble the instruction to provide more context.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-8-alexandre.chartre@oracle.com
2025-11-21 15:30:08 +01:00
Alexandre Chartre
d4e13c2149
objtool: Store instruction disassembly result
...
When disassembling an instruction store the result instead of directly
printing it.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-7-alexandre.chartre@oracle.com
2025-11-21 15:30:08 +01:00
Alexandre Chartre
5d859dff26
objtool: Print symbol during disassembly
...
Print symbols referenced during disassembly instead of just printing
raw addresses. Also handle address relocation.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-6-alexandre.chartre@oracle.com
2025-11-21 15:30:07 +01:00
Alexandre Chartre
5995330382
objtool: Disassemble code with libopcodes instead of running objdump
...
objtool executes the objdump command to disassemble code. Use libopcodes
instead to have more control about the disassembly scope and output.
If libopcodes is not present then objtool is built without disassembly
support.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-4-alexandre.chartre@oracle.com
2025-11-21 15:30:07 +01:00
Alexandre Chartre
1013f2e37b
objtool: Create disassembly context
...
Create a structure to store information for disassembling functions.
For now, it is just a wrapper around an objtool file.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-3-alexandre.chartre@oracle.com
2025-11-21 15:30:06 +01:00
Alexandre Chartre
55d2a473f3
objtool: Move disassembly functions to a separated file
...
objtool disassembles functions which have warnings. Move the code
to do that to a dedicated file. The code is just moved, it is not
changed.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com >
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org >
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org >
Link: https://patch.msgid.link/20251121095340.464045-2-alexandre.chartre@oracle.com
2025-11-21 15:30:06 +01:00