disas: Allow linking multiple disassemblers in a heterogeneous binary
Subsystems (2)
cover disas: Allow linking multiple disassemblers in a heterogeneous binary
Hi,
This series is an experiment to link multiple disassembler in the same system binary. At least in my prototype I wanted to get 3: x86 host and microblaze/xtensa targets.
Instead of having meson.build select one pair of host+target, we let targets to be selected by Kconfig. By default each target keeps selecting its disassembler, so there is no change in current uses of 1 target per binary.
Unfortunately I couldn't generalize to user emulation because we don't use Kconfig there.
Philippe Mathieu-Daudé (6):
target: Only link capstone to targets requiring it target/hexagon: Add Kconfig file target/xtensa: Move xtensa-isa.c to common_ss[]
disas: Have each system target select its disassembler
Kconfig: Expose host CONFIG_CAPSTONE definition
disas: Select capstone targets by default
meson.build | 4 ++- Kconfig | 1 + Kconfig.host | 3 ++ disas/Kconfig | 60 +++++++++++++++++++++++++++++++++++++++ disas/meson.build | 1 - target/Kconfig | 1 + target/alpha/Kconfig | 1 + target/arm/meson.build | 1 + target/avr/Kconfig | 1 + target/hexagon/Kconfig | 3 ++ target/hppa/Kconfig | 1 + target/i386/Kconfig | 1 + target/i386/meson.build | 1 + target/loongarch/Kconfig | 1 + target/m68k/Kconfig | 1 + target/microblaze/Kconfig | 1 + target/mips/Kconfig | 1 + target/openrisc/Kconfig | 1 + target/ppc/Kconfig | 1 + target/ppc/meson.build | 1 + target/riscv/Kconfig | 2 ++ target/rx/Kconfig | 1 + target/s390x/Kconfig | 1 + target/s390x/meson.build | 1 + target/sh4/Kconfig | 1 + target/sparc/Kconfig | 2 ++ target/tricore/Kconfig | 1 + target/xtensa/Kconfig | 1 + target/xtensa/meson.build | 3 +- 29 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 disas/Kconfig create mode 100644 target/hexagon/Kconfig
Signature · 1 line
2.47.1
RFC PATCH 1/6 target: Only link capstone to targets requiring it
No need to link capstone to targets which don't use it.
--- disas/meson.build | 1 - target/arm/meson.build | 1 + target/i386/meson.build | 1 + target/ppc/meson.build | 1 + target/s390x/meson.build | 1 + 5 files changed, 4 insertions(+), 1 deletion(-)
disas/meson.build +0 -1
@@ -20,4 +20,3 @@ common_ss.add(when: 'CONFIG_TCG', if_true: files( )) common_ss.add(files('disas-common.c')) system_ss.add(files('disas-mon.c')) -specific_ss.add(capstone)
target/arm/meson.build +1 -0
@@ -1,4 +1,5 @@ arm_ss = ss.source_set() +arm_ss.add(capstone) arm_ss.add(files( 'cpu.c', 'debug_helper.c',
target/i386/meson.build +1 -0
@@ -1,4 +1,5 @@ i386_ss = ss.source_set() +i386_ss.add(capstone) i386_ss.add(files( 'cpu.c', 'gdbstub.c',
target/ppc/meson.build +1 -0
@@ -1,4 +1,5 @@ ppc_ss = ss.source_set() +ppc_ss.add(capstone) ppc_ss.add(files( 'cpu-models.c', 'cpu.c',
target/s390x/meson.build +1 -0
@@ -1,4 +1,5 @@ s390x_ss = ss.source_set() +s390x_ss.add(capstone) s390x_ss.add(files( 'cpu.c', 'cpu_features.c',
Signature · 1 line
2.47.1
Re: [RFC PATCH 1/6] target: Only link capstone to targets requiring it
Quoted 16 lines · Philippe Mathieu-Daudé
No need to link capstone to targets which don't use it.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- disas/meson.build | 1 - target/arm/meson.build | 1 + target/i386/meson.build | 1 + target/ppc/meson.build | 1 + target/s390x/meson.build | 1 + 5 files changed, 4 insertions(+), 1 deletion(-)disas/meson.build +0
-0
disas/meson.build common_ss.add(when: 'CONFIG_TCG', if_true: files( · line 23
Quoted 4 lines
disas/meson.build +0
-1@@ -20,4 +20,3 @@ common_ss.add(when: 'CONFIG_TCG', if_true: files( )) common_ss.add(files('disas-common.c')) system_ss.add(files('disas-mon.c')) -specific_ss.add(capstone)
You need to think about which hosts require capstone as well, which is most of them. This will help almost never.
r~
Re: [RFC PATCH 1/6] target: Only link capstone to targets requiring it
Quoted 12 lines · Richard Henderson
Quoted 11 lines · Philippe Mathieu-Daudé
No need to link capstone to targets which don't use it.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
disas/meson.build | 1 -
target/arm/meson.build | 1 +
target/i386/meson.build | 1 +
target/ppc/meson.build | 1 +
target/s390x/meson.build | 1 +5 files changed, 4 insertions(+), 1 deletion(-)
Quoted 12 lines
disas/meson.build common_ss.add(when: 'CONFIG_TCG', if_true: files( · line 23
Quoted 9 lines
disas/meson.build +0
-1@@ -20,4 +20,3 @@ common_ss.add(when: 'CONFIG_TCG', if_true: files( )) common_ss.add(files('disas-common.c')) system_ss.add(files('disas-mon.c')) -specific_ss.add(capstone)You need to think about which hosts require capstone as well, which is most of them. This will help almost never.
Right, good point.
RFC PATCH 2/6 target/hexagon: Add Kconfig file
In reply to Philippe Mathieu-DaudéKeep the Hexagon target in line with others.
--- target/Kconfig | 1 + target/hexagon/Kconfig | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 target/hexagon/Kconfig
target/Kconfig +1 -0
@@ -1,6 +1,7 @@ source alpha/Kconfig source arm/Kconfig source avr/Kconfig +source hexagon/Kconfig source hppa/Kconfig source i386/Kconfig source loongarch/Kconfig
target/hexagon/Kconfig new file +2 -0
@@ -0,0 +1,2 @@ +config HEXAGON + bool
Signature · 1 line
2.47.1
Re: [RFC PATCH 2/6] target/hexagon: Add Kconfig file
Quoted 4 lines · Philippe Mathieu-Daudé
Keep the Hexagon target in line with others.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 25 lines
target/Kconfig | 1 + target/hexagon/Kconfig | 2 ++ 2 files changed, 3 insertions(+)create mode 100644 target/hexagon/Kconfig
target/Kconfig +1
-0@@ -1,6 +1,7 @@ source alpha/Kconfig source arm/Kconfig source avr/Kconfig +source hexagon/Kconfig source hppa/Kconfig source i386/Kconfig source loongarch/Kconfigtarget/hexagon/Kconfig new file +2
-0@@ -0,0 +1,2 @@ +config HEXAGON + bool
RFC PATCH 3/6 target/xtensa: Move xtensa-isa.c to common_ss[]
In reply to Philippe Mathieu-DaudéThe Xtensa disassembler (selected with CONFIG_XTENSA_DIS=y) uses methods defined in xtensa-isa.c, so this file has to be compiled when the disassembler is linked.
--- target/xtensa/meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/xtensa/meson.build +2 -1
@@ -12,9 +12,10 @@ xtensa_ss.add(files( 'op_helper.c', 'translate.c', 'win_helper.c', - 'xtensa-isa.c', )) +common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa-isa.c')) + xtensa_system_ss = ss.source_set() xtensa_system_ss.add(files( 'dbg_helper.c',
Signature · 1 line
2.47.1
Re: [RFC PATCH 3/6] target/xtensa: Move xtensa-isa.c to common_ss[]
Quoted 15 lines · Philippe Mathieu-Daudé
The Xtensa disassembler (selected with
CONFIG_XTENSA_DIS=y) uses methods defined inxtensa-isa.c, so this file has to be compiled when the disassembler is linked.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/xtensa/meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/xtensa/meson.build +0
-0@@ -12,9 +12,10 @@ xtensa_ss.add(files( 'op_helper.c',
target/xtensa/meson.build xtensa_ss.add(files( · line 21
Quoted 10 lines
target/xtensa/meson.build +2
-1'translate.c', 'win_helper.c', - 'xtensa-isa.c', )) +common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa-isa.c')) + xtensa_system_ss = ss.source_set() xtensa_system_ss.add(files( 'dbg_helper.c',
r~
RFC PATCH 4/6 disas: Have each system target select its disassembler
In reply to Philippe Mathieu-DaudéNo change for host or user emulation.
For system emulation, each target explicitly selects its disassembler.
This change allows selecting more than two (host + target) disassemblers in a binary supporting multiple targets.
--- meson.build | 3 ++- Kconfig | 1 + disas/Kconfig | 56 +++++++++++++++++++++++++++++++++++++++ target/alpha/Kconfig | 1 + target/avr/Kconfig | 1 + target/hexagon/Kconfig | 1 + target/hppa/Kconfig | 1 + target/i386/Kconfig | 1 + target/loongarch/Kconfig | 1 + target/m68k/Kconfig | 1 + target/microblaze/Kconfig | 1 + target/mips/Kconfig | 1 + target/openrisc/Kconfig | 1 + target/ppc/Kconfig | 1 + target/riscv/Kconfig | 2 ++ target/rx/Kconfig | 1 + target/s390x/Kconfig | 1 + target/sh4/Kconfig | 1 + target/sparc/Kconfig | 2 ++ target/tricore/Kconfig | 1 + target/xtensa/Kconfig | 1 + 21 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 disas/Kconfig
meson.build +2 -1
@@ -3319,7 +3319,8 @@ foreach target : target_dirs endif foreach k, v: disassemblers - if host_arch.startswith(k) or config_target['TARGET_BASE_ARCH'].startswith(k) + if host_arch.startswith(k) \ + or (target.endswith('-user') and config_target['TARGET_BASE_ARCH'].startswith(k)) foreach sym: v config_target += { sym: 'y' } endforeach
Kconfig +1 -0
@@ -1,6 +1,7 @@ source Kconfig.host source backends/Kconfig source accel/Kconfig +source disas/Kconfig source target/Kconfig source hw/Kconfig source semihosting/Kconfig
disas/Kconfig new file +56 -0
56 lines not on this page · raw message
target/alpha/Kconfig +1 -0
@@ -1,2 +1,3 @@ config ALPHA bool + select ALPHA_DIS
target/avr/Kconfig +1 -0
@@ -1,2 +1,3 @@ config AVR bool + select AVR_DIS
target/hexagon/Kconfig +1 -0
@@ -1,2 +1,3 @@ config HEXAGON bool + select HEXAGON_DIS
target/hppa/Kconfig +1 -0
@@ -1,2 +1,3 @@ config HPPA bool + select HPPA_DIS
target/i386/Kconfig +1 -0
@@ -1,5 +1,6 @@ config I386 bool + select I386_DIS select APIC # kvm_arch_fixup_msi_route() needs to access PCIDevice select PCI if KVM
target/loongarch/Kconfig +1 -0
@@ -1,2 +1,3 @@ config LOONGARCH64 bool + select LOONGARCH_DIS
target/m68k/Kconfig +1 -0
@@ -1,3 +1,4 @@ config M68K bool + select M68K_DIS imply SEMIHOSTING if TCG
target/microblaze/Kconfig +1 -0
@@ -1,3 +1,4 @@ config MICROBLAZE bool + select MICROBLAZE_DIS select DEVICE_TREE # needed by boot.c
target/mips/Kconfig +1 -0
@@ -1,5 +1,6 @@ config MIPS bool + select MIPS_DIS imply SEMIHOSTING if TCG config MIPS64
target/openrisc/Kconfig +1 -0
@@ -1,3 +1,4 @@ config OPENRISC bool + select OPENRISC_DIS select DEVICE_TREE # needed by boot.c
target/ppc/Kconfig +1 -0
@@ -1,5 +1,6 @@ config PPC bool + select PPC_DIS config PPC64 bool
target/riscv/Kconfig +2 -0
@@ -1,9 +1,11 @@ config RISCV32 bool + select RISCV_DIS select ARM_COMPATIBLE_SEMIHOSTING if TCG select DEVICE_TREE # needed by boot.c config RISCV64 bool + select RISCV_DIS select ARM_COMPATIBLE_SEMIHOSTING if TCG select DEVICE_TREE # needed by boot.c
target/rx/Kconfig +1 -0
@@ -1,2 +1,3 @@ config RX bool + select RX_DIS
target/s390x/Kconfig +1 -0
@@ -1,5 +1,6 @@ config S390X bool + select S390_DIS select PCI select S390_FLIC
target/sh4/Kconfig +1 -0
@@ -1,4 +1,5 @@ config SH4 bool + select SH4_DIS # needed for sh_intc_get_pending_vector select SH_INTC
target/sparc/Kconfig +2 -0
@@ -1,5 +1,7 @@ config SPARC bool + select SPARC_DIS config SPARC64 bool + select SPARC_DIS
target/tricore/Kconfig +1 -0
@@ -1,2 +1,3 @@ config TRICORE bool + select TRICORE_DIS
target/xtensa/Kconfig +1 -0
@@ -1,3 +1,4 @@ config XTENSA bool imply SEMIHOSTING if TCG + select XTENSA_DIS
Signature · 1 line
2.47.1
RFC PATCH 5/6 Kconfig: Expose host CONFIG_CAPSTONE definition
In reply to Philippe Mathieu-Daudé--- meson.build | 1 + Kconfig.host | 3 +++ 2 files changed, 4 insertions(+)
meson.build +1 -0
@@ -3224,6 +3224,7 @@ host_kconfig = \ (have_ivshmem ? ['CONFIG_IVSHMEM=y'] : []) + \ (opengl.found() ? ['CONFIG_OPENGL=y'] : []) + \ (libcbor.found() ? ['CONFIG_LIBCBOR=y'] : []) + \ + (capstone.found() ? ['CONFIG_CAPSTONE=y'] : []) + \ (gnutls.found() ? ['CONFIG_GNUTLS=y'] : []) + \ (x11.found() ? ['CONFIG_X11=y'] : []) + \ (fdt.found() ? ['CONFIG_FDT=y'] : []) + \
Kconfig.host +3 -0
@@ -61,3 +61,6 @@ config HV_BALLOON_POSSIBLE config HAVE_RUST bool + +config CAPSTONE + bool
Signature · 1 line
2.47.1
RFC PATCH 6/6 disas: Select capstone targets by default
In reply to Philippe Mathieu-DaudéWhen capstone is available, we get ARM/X86/PPC/S390X disassemblers in common_ss[] for free.
--- disas/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
disas/Kconfig +4 -0
@@ -3,6 +3,7 @@ config ALPHA_DIS config ARM_DIS bool + default y if CAPSTONE config AVR_DIS bool
@@ -15,6 +16,7 @@ config HPPA_DIS config I386_DIS bool + default y if CAPSTONE config LOONGARCH_DIS bool
@@ -33,6 +35,7 @@ config OPENRISC_DIS config PPC_DIS bool + default y if CAPSTONE config RISCV_DIS bool
@@ -42,6 +45,7 @@ config RX_DIS config S390_DIS bool + default y if CAPSTONE config SH4_DIS bool
Signature · 1 line
2.47.1
Re: [RFC PATCH 6/6] disas: Select capstone targets by default
Quoted 7 lines · Philippe Mathieu-Daudé
When capstone is available, we get ARM/X86/PPC/S390X disassemblers in common_ss[] for free.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- disas/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
Hopefully starting with capstone 6 we'll be able to add more.
r~