aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Di Sera <[email protected]>2025-07-08 12:03:25 +0200
committerLuca Di Sera <[email protected]>2025-07-08 19:40:03 +0200
commit80e787d6312aff33542fbfeeec86aaeb1f90e78a (patch)
treef2cb41c7cb6de6a0806d1beac06c441f4ecc75cd
parent61ab3169447e1ec28f22eda3cd97e19a35a6d747 (diff)
Allow udis86 generation scripts to work with a more modern python
V4's baseline JIT uses some old JavaScriptCore code to optimize functions. As part of the offering, it is possible to use a disassembler, if enabled, to peek into the code that the JIT has generated for a function. For i386 and x86_64 udis86 is used, of which we bundle a very old version. To build and make use of udis86 it is necessary to generate some code running some bundled python scripts. The scripts are still written for a python2 target, which has long been sunsetted, making the scripts difficult to run on more modern systems. To allow the scripts to be run more easily, some modifications were made to support more modern pythons versions. In particular, print statements were modified to print functions. Furthermore, usages of the division operator("/") were modified to the integer division operator("//"), as the meaning of "/" was changed to non-integer division between python 2 and 3. Finally, a usage of the sort method was modified with self assignment to a `sorted()` value, due to python 3 not returning a list anymore, which has a sort method, on dict's `items` method. The changes are expected to mostly be semantically compatible, albeit it wasn't ascertained whether the behavior of other parts of the script might have been silently hit when running on a more modern python version. Informally, the script was used with a python 3.13 version, and the generated code was used to disassemble a few jitted function with success during an unrelated bug investigation. Change-Id: Ide0bcf4d29a51759f9bb9bd07d940562a8cfcc04 Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r--src/3rdparty/masm/disassembler/udis86/itab.py6
-rw-r--r--src/3rdparty/masm/disassembler/udis86/ud_opcode.py14
-rw-r--r--src/3rdparty/masm/disassembler/udis86/ud_optable.py12
3 files changed, 16 insertions, 16 deletions
diff --git a/src/3rdparty/masm/disassembler/udis86/itab.py b/src/3rdparty/masm/disassembler/udis86/itab.py
index 07e20a6e10..443ee4ee79 100644
--- a/src/3rdparty/masm/disassembler/udis86/itab.py
+++ b/src/3rdparty/masm/disassembler/udis86/itab.py
@@ -268,13 +268,13 @@ class UdItabGenerator( ud_opcode.UdOpcodeTables ):
opr = e[ 'operands' ]
for i in range(len(opr)):
if not (opr[i] in self.OperandDict.keys()):
- print "error: invalid operand declaration: %s\n" % opr[i]
+ print("error: invalid operand declaration: %s\n" % opr[i])
opr_c[i] = "O_" + opr[i]
opr = "%s %s %s" % (opr_c[0] + ",", opr_c[1] + ",", opr_c[2])
for p in e['prefixes']:
if not ( p in self.PrefixDict.keys() ):
- print "error: invalid prefix specification: %s \n" % pfx
+ print("error: invalid prefix specification: %s \n" % pfx)
pfx_c.append( self.PrefixDict[p] )
if len(e['prefixes']) == 0:
pfx_c.append( "P_none" )
@@ -315,7 +315,7 @@ class UdItabGenerator( ud_opcode.UdOpcodeTables ):
self.ItabH.write("\n/* itab entry operand definitions */\n");
operands = self.OperandDict.keys()
- operands.sort()
+ operands = sorted(operands)
for o in operands:
self.ItabH.write("#define O_%-7s { %-12s %-8s }\n" %
(o, self.OperandDict[o][0] + ",", self.OperandDict[o][1]));
diff --git a/src/3rdparty/masm/disassembler/udis86/ud_opcode.py b/src/3rdparty/masm/disassembler/udis86/ud_opcode.py
index f301b52461..336803657f 100644
--- a/src/3rdparty/masm/disassembler/udis86/ud_opcode.py
+++ b/src/3rdparty/masm/disassembler/udis86/ud_opcode.py
@@ -115,9 +115,9 @@ class UdOpcodeTables:
'/mod' : lambda v: '00' if v == '!11' else '01',
# Mode extensions:
# (16, 32, 64) => (00, 01, 02)
- '/o' : lambda v: "%02x" % (int(v) / 32),
- '/a' : lambda v: "%02x" % (int(v) / 32),
- '/m' : lambda v: "%02x" % (int(v) / 32),
+ '/o' : lambda v: "%02x" % (int(v) // 32),
+ '/a' : lambda v: "%02x" % (int(v) // 32),
+ '/m' : lambda v: "%02x" % (int(v) // 32),
'/sse' : lambda v: UdOpcodeTables.OpcExtIndex['sse'][v]
}
@@ -218,17 +218,17 @@ class UdOpcodeTables:
self.parse(self.OpcodeTable0, insn)
def print_table( self, table, pfxs ):
- print "%s |" % pfxs
+ print("%s |" % pfxs)
keys = table[ 'entries' ].keys()
if ( len( keys ) ):
keys.sort()
for idx in keys:
e = table[ 'entries' ][ idx ]
if e[ 'type' ] == 'insn':
- print "%s |-<%s>" % ( pfxs, idx ),
- print "%s %s" % ( e[ 'mnemonic' ], ' '.join( e[ 'operands'] ) )
+ print("%s |-<%s>" % ( pfxs, idx )),
+ print("%s %s" % ( e[ 'mnemonic' ], ' '.join( e[ 'operands'] ) ))
else:
- print "%s |-<%s> %s" % ( pfxs, idx, e['type'] )
+ print("%s |-<%s> %s" % ( pfxs, idx, e['type'] ))
self.print_table( e, pfxs + ' |' )
def print_tree( self ):
diff --git a/src/3rdparty/masm/disassembler/udis86/ud_optable.py b/src/3rdparty/masm/disassembler/udis86/ud_optable.py
index 5b5c55d3b8..0350643fd2 100644
--- a/src/3rdparty/masm/disassembler/udis86/ud_optable.py
+++ b/src/3rdparty/masm/disassembler/udis86/ud_optable.py
@@ -50,7 +50,7 @@ class UdOptableXmlParser:
elif def_node.localName == 'vendor':
ven = ( def_node.firstChild.data );
else:
- print "warning: invalid node - %s" % def_node.localName
+ print("warning: invalid node - %s" % def_node.localName)
continue
return ( pfx, opc, opr, ven )
@@ -65,7 +65,7 @@ class UdOptableXmlParser:
if not insnNode.localName:
continue
if insnNode.localName != "instruction":
- print "warning: invalid insn node - %s" % insnNode.localName
+ print("warning: invalid insn node - %s" % insnNode.localName)
continue
mnemonic = insnNode.getElementsByTagName( 'mnemonic' )[ 0 ].firstChild.data
@@ -84,11 +84,11 @@ class UdOptableXmlParser:
def printFn( pfx, mnm, opc, opr, ven ):
- print 'def: ',
+ print('def: '),
if len( pfx ):
- print ' '.join( pfx ),
- print "%s %s %s %s" % \
- ( mnm, ' '.join( opc ), ' '.join( opr ), ven )
+ print(' '.join( pfx )),
+ print("%s %s %s %s" % \
+ ( mnm, ' '.join( opc ), ' '.join( opr ), ven ))
def parse( xml, callback ):