Hi Kevin,
I guess it depends on how many other targets need to deal with the
same problem, and how much their maintainers want to cope with the
change on their side.
Creating multiple disassemblers is wasteful, but not critical to tools
like objdump, that are rarely on the hot path. It would be
simpler/quicker to instantiate them on objdump and then, based on the
Thumb bit, it chooses one or the other. However, I think this would
not be the best solution for some reasons:
1. This is disassembler logic, and having objdump doing this on a
higher level means that other tools that (eventually) need the same
functionality will have to re-implement.
2. It shouldn't be that hard to join the ARM and Thumb disassembler,
given that they're on the same file, share most of the static
functions and could easily delegate with getInstruction() deciding
which to use: getThumbInstruction() or getARMInstruction() and
renaming Thumb/ARMDisassembler functions to match.
Though, I haven't got my hands on the disassembler that much, so other
people with more experience in that area could chime in and give more
reasons on either side.
My personal opinion is that it'd be more elegant and stable that way,
and any work we have to do now would compensate in the future, but
other back-end maintainers could disagree.
cheers,
--renato
Mainly lldb, I guess, which probably has to do some sort of magic, too.
> As a maintainer of darwin’s otool(1) for some 20 plus years and plugging in
> some 9 or more different disassemblers the use if two llvm disassembler’s for
> 32-bit arm is no big deal at all. Heck it still has the old arm disassemblers in
> it and many other old ones and it is very stable and I rarely if ever have to touch
> those interfaces.
I don't think it's that much uglier to use multiple disassemblers for
the same target when you already use for different targets, and as you
said, you already have a way to use a collection of them on demand in
otool, so that wouldn't be much of a new hack.
But I can't opine on objdump's design decisions. All I can say is that
I don't think the changes in the ARM back-end wouldn't be that
problematic if you decide to merge the disassemblers.
Sure. Probably the easiest way would be to take all of the disparate
classes and throw them under the MCSubtargetInfo as best as can be
done, then you can just create a single object for each target you
want to disassemble for in the binary. arm/thumb mips/mips16 might be
a bit more difficult as you'll need to swap on a function by function
basis, but as long as you've got an index of subtargets to handle
disassembly it should be possible. Right now the arm/thumb interface
is a bit wonky there, but I think mips/mips16 should work - at least
it does for code generation, I haven't looked heavily at the
disassembler in a while.
If you're interested in going down this path though I'll give it some
thought and see what I can do.
-eric
Wouldn't you hit a similar problem in x86 if you were disassembling a section on code that switched from 16 bit real mode to 32 bit or 64 bit mode?