Skip to content

Commit 9c5b48b

Browse files
authored
AArch64 update to LLVM 18 (#2298)
* Run clang-format * Remove arm.h header from AArch64 files * Update all AArch64 module files to LLVM-18. * Add check if the differs save file is up-to-date with the current files. * Add new generator for MC test trnaslation. * Fix warnings * Update generated AsmWriter files * Remove unused variable * Change MCPhysReg type to int16_t as LLVM 18 dictates. With LLVM 18 the MCPhysReg value's type is changed to int16_t. If we update modules to LLVM 18, they will generate compiler warnings that uint16_t* should not be casted to int16_t*. This makes changing the all tables to int16_t necessary, because the alternative is to duplicate all MCPhysReg related code. Which is even worse. * Assign enum values to raw_struct member * Add printAdrAdrpLabel def * Add header to regression test files. * Write files to build dir and ignore more parsing errors. * Fix parsing of MC test files. * Reset parser after every block * Add write and patch header step. * Add and update MC tests for AArch64 * Fix clang-tidy warnings * Don't warn about padding issues. They break automatically initialized structs we can not change easily. * Fix: Incorrect access of LLVM instruction descriptions. * Initialize DecoderComplete flag * Add more mapping and flag details * Add function to get MCInstDesc from table * Fix incorrect memory operand access types. * Fix test where memory was not written, ut only read. * Attempt to fix Windows build * Fix 2268 The enum values were different and hence lead to different decoding. * Refactor SME operands. - Splits SME operands in Matrix and Predicate operands. - Fixes general problems of incorrect detections with the vector select/index operands of predicate registers. - Simplifies code. * Fix up typo in WRITE * Print actual path to struct fields * Add Registers of SME operands to the reg-read list * Add tests for SME operands. * Use Capstone reg enum for comparison * Fix tests: 'Vector arra...' to 'operands[x].vas' * Add the developer fuzz option. * Fix Python bindings for SME operands * Fix variable shadowing. * Fix clang-tidy warnings * Add missing break. * Fix varg usage * Brackets for case * Handle AArch64_OP_GROUP_AdrAdrpLabel * Fix endian issue with fuzzing start bytes * Move previous sme.pred to it's own operand type. * Fix calculation for imm ranges * Print list member flag * Fix up operand strings for cstest * Do only a shallow clone of the cmocka stable branch * Fix: Don't categorize ZT0 as a SME matrix operand. * Remove unused code. * Add flag to distinguish Vn and Qn registers. * Add all registers to detail struct, even if emitted in the asm text * Fix: Increment op count after each list member is added. * Remove implicit write to NZCV for MSR Imm instructions. * Handle several alias operands. * Add details for zero alias with za0.h * Add SME tile to write list if written * Add write access flags to operands which are zeroed. * Add SME tests of #2285 * Fix tests with latest syntax changes. * Fix segfault if memory operand is only a label without register. * Fix python bindings * Attempt to fix clang-tidy warning for some configurations. * Add missing test file (accidentially blocked by gitignore.) * Print clang-tidy version before linting. * Update differ save file * Formatting * Use clang-tidy-15 as if possible. * Remove search patterns for MC tests, since they need to be reworked anyways. * Enum to upper case change * Add information to read the OSS fuzz result. * Fix special case of SVE2 operands. Apparently ZT0 registers can an index attached, get which is BOUND to it. We have no "index for reg" field. So it is simply saved as an immediate. * Handle LLVM expressions without asserts. * Ensure choices are always saved. * OP_GROUP enums can't be all upper case because they contain type information. * Fix compatibility header patching * Update saved_choices.json * Allow mode == None in test_corpus
1 parent 8ce088b commit 9c5b48b

File tree

506 files changed

+154143
-118862
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

506 files changed

+154143
-118862
lines changed

.github/workflows/CITest.yml

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ jobs:
132132
clang -lcapstone src/test_arm64_compatibility_header.c -o test_arm64_compatibility_header
133133
fi
134134
./test_arm64_compatibility_header
135-
cd "$(git rev-parse --show-toplevel)"
136135
137136
- name: cstool - reaches disassembler engine
138137
run: |

.github/workflows/auto-sync.yml

+5
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ jobs:
6666
- name: Test Header patcher
6767
run: |
6868
python -m unittest src/autosync/Tests/test_header_patcher.py
69+
python -m unittest src/autosync/Tests/test_mcupdater.py
70+
71+
- name: Differ - Test save file is up-to-date
72+
run: |
73+
./src/autosync/cpptranslator/Differ.py -a AArch64 --check_saved

.github/workflows/clang-tidy.yml

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
CC=clang sudo cmake --build . --config Release
2727
cd ..
2828
29+
- name: Install clang-tidy-15
30+
run: |
31+
sudo apt install clang-tidy-15
32+
2933
- name: Check for warnings
3034
env:
3135
base_sha: ${{ github.event.pull_request.base.sha }}

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ if(CAPSTONE_BUILD_CSTEST)
890890
PREFIX extern
891891
GIT_REPOSITORY "https://git.cryptomilk.org/projects/cmocka.git"
892892
GIT_TAG "origin/stable-1.1"
893+
GIT_SHALLOW true
893894
CONFIGURE_COMMAND cmake -DBUILD_SHARED_LIBS=OFF ../cmocka_ext/
894895
BUILD_COMMAND cmake --build . --config Release
895896
INSTALL_COMMAND ""

MCInst.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* Capstone Disassembly Engine */
22
/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */
3-
43
#if defined(CAPSTONE_HAS_OSXKERNEL)
54
#include <Availability.h>
65
#include <libkern/libkern.h>
@@ -11,6 +10,7 @@
1110
#include <string.h>
1211
#include <assert.h>
1312

13+
#include "MCInstrDesc.h"
1414
#include "MCInst.h"
1515
#include "utils.h"
1616

@@ -105,12 +105,12 @@ bool MCOperand_isValid(const MCOperand *op)
105105

106106
bool MCOperand_isReg(const MCOperand *op)
107107
{
108-
return op->Kind == kRegister;
108+
return op->Kind == kRegister || op->MachineOperandType == kRegister;
109109
}
110110

111111
bool MCOperand_isImm(const MCOperand *op)
112112
{
113-
return op->Kind == kImmediate;
113+
return op->Kind == kImmediate || op->MachineOperandType == kImmediate;
114114
}
115115

116116
bool MCOperand_isFPImm(const MCOperand *op)
@@ -224,16 +224,26 @@ bool MCInst_isPredicable(const MCInstrDesc *MIDesc)
224224
/// Checks if tied operands exist in the instruction and sets
225225
/// - The writeback flag in detail
226226
/// - Saves the indices of the tied destination operands.
227-
void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDesc)
228-
{
229-
const MCOperandInfo *OpInfo = InstDesc[MCInst_getOpcode(MI)].OpInfo;
230-
unsigned short NumOps = InstDesc[MCInst_getOpcode(MI)].NumOperands;
227+
void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDescTable, unsigned tbl_size)
228+
{
229+
const MCInstrDesc *InstDesc = NULL;
230+
const MCOperandInfo *OpInfo = NULL;
231+
unsigned short NumOps = 0;
232+
if (MI->csh->arch == CS_ARCH_ARM) {
233+
// Uses old (pre LLVM 18) indexing method.
234+
InstDesc = &InstDescTable[MCInst_getOpcode(MI)];
235+
OpInfo = InstDescTable[MCInst_getOpcode(MI)].OpInfo;
236+
NumOps = InstDescTable[MCInst_getOpcode(MI)].NumOperands;
237+
} else {
238+
InstDesc = MCInstrDesc_get(MCInst_getOpcode(MI), InstDescTable, tbl_size);
239+
OpInfo = MCInstrDesc_get(MCInst_getOpcode(MI), InstDescTable, tbl_size)->OpInfo;
240+
NumOps = MCInstrDesc_get(MCInst_getOpcode(MI), InstDescTable, tbl_size)->NumOperands;
241+
}
231242

232-
unsigned i;
233-
for (i = 0; i < NumOps; ++i) {
243+
for (unsigned i = 0; i < NumOps; ++i) {
234244
if (MCOperandInfo_isTiedToOp(&OpInfo[i])) {
235245
int idx = MCOperandInfo_getOperandConstraint(
236-
&InstDesc[MCInst_getOpcode(MI)], i,
246+
InstDesc, i,
237247
MCOI_TIED_TO);
238248

239249
if (idx == -1)

MCInst.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void MCInst_addOperand2(MCInst *inst, MCOperand *Op);
159159

160160
bool MCInst_isPredicable(const MCInstrDesc *MIDesc);
161161

162-
void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDesc);
162+
void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDescTable, unsigned tbl_size);
163163

164164
bool MCInst_opIsTied(const MCInst *MI, unsigned OpNum);
165165

MCInstrDesc.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ int MCOperandInfo_getOperandConstraint(const MCInstrDesc *InstrDesc,
3838
return (OpInfo.Constraints >> ValuePos) & 0xf;
3939
}
4040
return -1;
41-
}
41+
}
42+
43+
/// Returns the instruction description for the given MCInst opcode.
44+
/// Function should be called like:
45+
/// MCInstrDesc_get(MCInst_getOpcode(MI), ARCHInstDesc, ARR_SIZE(ARCHInstDesc));
46+
const MCInstrDesc *MCInstrDesc_get(unsigned opcode, const MCInstrDesc *table, unsigned tbl_size) {
47+
return &table[tbl_size - 1 - opcode];
48+
}

MCInstrDesc.h

+4
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,9 @@ bool MCOperandInfo_isTiedToOp(const MCOperandInfo *m);
163163
int MCOperandInfo_getOperandConstraint(const MCInstrDesc *OpInfo,
164164
unsigned OpNum,
165165
MCOI_OperandConstraint Constraint);
166+
const MCInstrDesc *MCInstrDesc_get(unsigned opcode,
167+
const MCInstrDesc *table,
168+
unsigned tbl_size);
169+
166170

167171
#endif

MCRegisterInfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/// An unsigned integer type large enough to represent all physical registers,
2525
/// but not necessarily virtual registers.
26-
typedef uint16_t MCPhysReg;
26+
typedef int16_t MCPhysReg;
2727
typedef const MCPhysReg* iterator;
2828

2929
typedef struct MCRegisterClass2 {

Mapping.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typedef struct insn_map {
3131
union {
3232
ppc_suppl_info ppc;
3333
loongarch_suppl_info loongarch;
34+
aarch64_suppl_info aarch64;
3435
} suppl_info; // Supplementary information for each instruction.
3536
#endif
3637
} insn_map;

0 commit comments

Comments
 (0)