From 69d224167f11cff5d0f78ed0cb0f02394ae32090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Sat, 20 Jan 2024 14:28:32 +0100 Subject: [PATCH] Fix warnings when building with CAPSTONE_DIET (#2249) --- arch/AArch64/AArch64GenAsmWriter.inc | 8 ++++++-- arch/AArch64/AArch64InstPrinter.c | 2 ++ arch/ARM/ARMGenAsmWriter.inc | 4 ++-- arch/ARM/ARMInstPrinter.c | 2 ++ arch/Alpha/AlphaGenAsmWriter.inc | 2 -- arch/BPF/BPFMapping.c | 12 ++++++++---- arch/EVM/EVMMapping.c | 2 +- arch/MOS65XX/MOS65XXDisassembler.c | 2 +- arch/PowerPC/PPCGenAsmWriter.inc | 4 ++-- arch/PowerPC/PPCInstPrinter.c | 2 ++ arch/TMS320C64x/TMS320C64xGenAsmWriter.inc | 2 ++ arch/X86/X86Mapping.c | 4 +++- cs.c | 2 ++ 13 files changed, 33 insertions(+), 15 deletions(-) diff --git a/arch/AArch64/AArch64GenAsmWriter.inc b/arch/AArch64/AArch64GenAsmWriter.inc index 491508372..e5be24932 100644 --- a/arch/AArch64/AArch64GenAsmWriter.inc +++ b/arch/AArch64/AArch64GenAsmWriter.inc @@ -21264,8 +21264,10 @@ getRegisterName(unsigned RegNo, unsigned AltIdx) { #ifdef PRINT_ALIAS_INSTR #undef PRINT_ALIAS_INSTR +#ifndef CAPSTONE_DIET static bool AArch64InstPrinterValidateMCOperand(const MCOperand *MCOp, unsigned PredicateIndex); +#endif static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) { #ifndef CAPSTONE_DIET static const PatternsForOpcode OpToPatterns[] = { @@ -33325,11 +33327,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) { #endif // CAPSTONE_DIET } +#ifndef CAPSTONE_DIET static void printCustomAliasOperand( MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, SStream *OS) { -#ifndef CAPSTONE_DIET switch (PrintMethodIdx) { default: assert(0 && "Unknown PrintMethod kind"); @@ -33524,9 +33526,10 @@ static void printCustomAliasOperand( printSysCROperand(MI, OpIdx, OS); break; } -#endif // CAPSTONE_DIET } +#endif // CAPSTONE_DIET +#ifndef CAPSTONE_DIET static bool AArch64InstPrinterValidateMCOperand(const MCOperand *MCOp, unsigned PredicateIndex) { switch (PredicateIndex) { @@ -33610,5 +33613,6 @@ static bool AArch64InstPrinterValidateMCOperand(const MCOperand *MCOp, } } } +#endif #endif // PRINT_ALIAS_INSTR diff --git a/arch/AArch64/AArch64InstPrinter.c b/arch/AArch64/AArch64InstPrinter.c index 2b83192c6..916c5888a 100644 --- a/arch/AArch64/AArch64InstPrinter.c +++ b/arch/AArch64/AArch64InstPrinter.c @@ -54,10 +54,12 @@ #define DEBUG_TYPE "asm-printer" +#ifndef CAPSTONE_DIET static void printCustomAliasOperand( MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, SStream *OS); +#endif #define DECLARE_printComplexRotationOp(Angle, Remainder) \ static void CONCAT(printComplexRotationOp, CONCAT(Angle, Remainder))( \ diff --git a/arch/ARM/ARMGenAsmWriter.inc b/arch/ARM/ARMGenAsmWriter.inc index 35f2fe3c8..4b26bc28d 100644 --- a/arch/ARM/ARMGenAsmWriter.inc +++ b/arch/ARM/ARMGenAsmWriter.inc @@ -13336,10 +13336,10 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) #endif // CAPSTONE_DIET } +#ifndef CAPSTONE_DIET void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, SStream *OS) { -#ifndef CAPSTONE_DIET switch (PrintMethodIdx) { default: assert(0 && "Unknown PrintMethod kind"); @@ -13354,7 +13354,7 @@ void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx, printMandatoryInvertedPredicateOperand(MI, OpIdx, OS); break; } -#endif // CAPSTONE_DIET } +#endif // CAPSTONE_DIET #endif // PRINT_ALIAS_INSTR diff --git a/arch/ARM/ARMInstPrinter.c b/arch/ARM/ARMInstPrinter.c index 4449aea6b..212887d1c 100644 --- a/arch/ARM/ARMInstPrinter.c +++ b/arch/ARM/ARMInstPrinter.c @@ -52,9 +52,11 @@ // Static function declarations. These are functions which have the same identifiers // over all architectures. Therefor they need to be static. +#ifndef CAPSTONE_DIET static void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, SStream *O); +#endif static void printOperand(MCInst *MI, unsigned OpNo, SStream *O); static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O); static void printRegName(SStream *OS, unsigned RegNo); diff --git a/arch/Alpha/AlphaGenAsmWriter.inc b/arch/Alpha/AlphaGenAsmWriter.inc index fcb3fcf0f..465a8148c 100644 --- a/arch/Alpha/AlphaGenAsmWriter.inc +++ b/arch/Alpha/AlphaGenAsmWriter.inc @@ -1501,9 +1501,7 @@ static const char *getRegisterName(unsigned RegNo) { #undef PRINT_ALIAS_INSTR static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) { -#ifndef CAPSTONE_DIET return false; -#endif // CAPSTONE_DIET } #endif // PRINT_ALIAS_INSTR diff --git a/arch/BPF/BPFMapping.c b/arch/BPF/BPFMapping.c index 3ba6e93cf..c2b797946 100644 --- a/arch/BPF/BPFMapping.c +++ b/arch/BPF/BPFMapping.c @@ -283,6 +283,7 @@ static bpf_insn op2insn_jmp(unsigned opcode) return BPF_INS_INVALID; } +#ifndef CAPSTONE_DIET static void update_regs_access(cs_struct *ud, cs_detail *detail, bpf_insn insn_id, unsigned int opcode) { @@ -357,6 +358,7 @@ static void update_regs_access(cs_struct *ud, cs_detail *detail, break; } } +#endif /* * 1. Convert opcode(id) to BPF_INS_* @@ -366,12 +368,12 @@ void BPF_get_insn_id(cs_struct *ud, cs_insn *insn, unsigned int opcode) { // No need to care the mode (cBPF or eBPF) since all checks has be done in // BPF_getInstruction, we can simply map opcode to BPF_INS_*. - cs_detail *detail; bpf_insn id = BPF_INS_INVALID; +#ifndef CAPSTONE_DIET + cs_detail *detail; bpf_insn_group grp; detail = insn->detail; -#ifndef CAPSTONE_DIET #define PUSH_GROUP(grp) do { \ if (detail) { \ detail->groups[detail->groups_count] = grp; \ @@ -379,7 +381,7 @@ void BPF_get_insn_id(cs_struct *ud, cs_insn *insn, unsigned int opcode) } \ } while(0) #else - #define PUSH_GROUP + #define PUSH_GROUP(grp) do {} while(0) #endif switch (BPF_CLASS(opcode)) { @@ -400,13 +402,15 @@ void BPF_get_insn_id(cs_struct *ud, cs_insn *insn, unsigned int opcode) PUSH_GROUP(BPF_GRP_ALU); break; case BPF_CLASS_JMP: - grp = BPF_GRP_JUMP; id = op2insn_jmp(opcode); +#ifndef CAPSTONE_DIET + grp = BPF_GRP_JUMP; if (id == BPF_INS_CALL || id == BPF_INS_CALLX) grp = BPF_GRP_CALL; else if (id == BPF_INS_EXIT) grp = BPF_GRP_RETURN; PUSH_GROUP(grp); +#endif break; case BPF_CLASS_RET: id = BPF_INS_RET; diff --git a/arch/EVM/EVMMapping.c b/arch/EVM/EVMMapping.c index fb36ab5e5..0f51a795d 100644 --- a/arch/EVM/EVMMapping.c +++ b/arch/EVM/EVMMapping.c @@ -15,7 +15,6 @@ static const cs_evm insns[256] = { #include "EVMMappingInsn.inc" }; -#endif // look for @id in @insns, given its size in @max. // return -1 if not found @@ -30,6 +29,7 @@ static int evm_insn_find(const cs_evm *insns, unsigned int max, unsigned int id) return (int)id; } +#endif // fill in details void EVM_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id) diff --git a/arch/MOS65XX/MOS65XXDisassembler.c b/arch/MOS65XX/MOS65XXDisassembler.c index c3d8c429b..9dc1662fb 100644 --- a/arch/MOS65XX/MOS65XXDisassembler.c +++ b/arch/MOS65XX/MOS65XXDisassembler.c @@ -20,11 +20,11 @@ static const struct OpInfo OpInfoTable[]= { }; +#ifndef CAPSTONE_DIET static const char* const RegNames[] = { "invalid", "A", "X", "Y", "P", "SP", "DP", "B", "K" }; -#ifndef CAPSTONE_DIET static const char* const GroupNames[] = { NULL, "jump", diff --git a/arch/PowerPC/PPCGenAsmWriter.inc b/arch/PowerPC/PPCGenAsmWriter.inc index 8a67424a7..e514e041f 100644 --- a/arch/PowerPC/PPCGenAsmWriter.inc +++ b/arch/PowerPC/PPCGenAsmWriter.inc @@ -15721,11 +15721,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) { #endif // CAPSTONE_DIET } +#ifndef CAPSTONE_DIET static void printCustomAliasOperand( MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, SStream *OS) { -#ifndef CAPSTONE_DIET switch (PrintMethodIdx) { default: assert(0 && "Unknown PrintMethod kind"); @@ -15755,7 +15755,7 @@ static void printCustomAliasOperand( printU5ImmOperand(MI, OpIdx, OS); break; } -#endif // CAPSTONE_DIET } +#endif // CAPSTONE_DIET #endif // PRINT_ALIAS_INSTR diff --git a/arch/PowerPC/PPCInstPrinter.c b/arch/PowerPC/PPCInstPrinter.c index 4b3c797fc..7ce0916fd 100644 --- a/arch/PowerPC/PPCInstPrinter.c +++ b/arch/PowerPC/PPCInstPrinter.c @@ -50,9 +50,11 @@ // Static function declarations. These are functions which have the same identifiers // over all architectures. Therefor they need to be static. +#ifndef CAPSTONE_DIET static void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, SStream *O); +#endif static void printOperand(MCInst *MI, unsigned OpNo, SStream *O); static void printPredicateOperand(MCInst *MI, unsigned OpNo, SStream *O, const char *Modifier); diff --git a/arch/TMS320C64x/TMS320C64xGenAsmWriter.inc b/arch/TMS320C64x/TMS320C64xGenAsmWriter.inc index a5242dae9..a4f2c7f29 100644 --- a/arch/TMS320C64x/TMS320C64xGenAsmWriter.inc +++ b/arch/TMS320C64x/TMS320C64xGenAsmWriter.inc @@ -295,6 +295,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI) { 0U }; +#ifndef CAPSTONE_DIET static const char AsmStrs[] = { /* 0 */ 'n', 'o', 'p', 9, 9, 0, /* 6 */ 's', 'u', 'b', '2', 9, 0, @@ -428,6 +429,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI) { /* 897 */ 'b', 9, 'n', 'r', 'p', 0, /* 903 */ 'l', 'i', 'f', 'e', 't', 'i', 'm', 'e', '_', 's', 't', 'a', 'r', 't', 0, }; +#endif // Emit the opcode for the instruction. uint32_t Bits = OpInfo[MCInst_getOpcode(MI)]; diff --git a/arch/X86/X86Mapping.c b/arch/X86/X86Mapping.c index 7dba7a97f..d23340d77 100644 --- a/arch/X86/X86Mapping.c +++ b/arch/X86/X86Mapping.c @@ -1712,7 +1712,6 @@ static bool valid_bnd(cs_struct *h, unsigned int opcode) // not found return false; } -#endif // return true if the opcode is XCHG [mem] static bool xchg_mem(unsigned int opcode) @@ -1727,6 +1726,7 @@ static bool xchg_mem(unsigned int opcode) return true; } } +#endif // given MCInst's id, find out if this insn is valid for REP prefix static bool valid_rep(cs_struct *h, unsigned int opcode) @@ -1783,6 +1783,7 @@ static bool valid_rep(cs_struct *h, unsigned int opcode) return false; } +#ifndef CAPSTONE_DIET // given MCInst's id, find if this is a "repz ret" instruction // gcc generates "repz ret" (f3 c3) instructions in some cases as an // optimization for AMD platforms, see: @@ -1800,6 +1801,7 @@ static bool valid_ret_repz(cs_struct *h, unsigned int opcode) // not found return false; } +#endif // given MCInst's id, find out if this insn is valid for REPE prefix static bool valid_repe(cs_struct *h, unsigned int opcode) diff --git a/cs.c b/cs.c index 840723f8a..6be33f496 100644 --- a/cs.c +++ b/cs.c @@ -563,6 +563,7 @@ cs_err CAPSTONE_API cs_close(csh *handle) // replace str1 in target with str2; target starts with str1 // output is put into result (which is array of char with size CS_MNEMONIC_SIZE) // return 0 on success, -1 on failure +#ifndef CAPSTONE_DIET static int str_replace(char *result, char *target, const char *str1, char *str2) { // only perform replacement if the output fits into result @@ -576,6 +577,7 @@ static int str_replace(char *result, char *target, const char *str1, char *str2) } else return -1; } +#endif /// The asm string sometimes has a leading space or tab. /// Here we remove it.