do not use constructor to enable archs, so code is more portable. suggested by Alex Ionescu
diff --git a/arch/AArch64/module.c b/arch/AArch64/module.c
index 4f0cbb3..e0b8413 100644
--- a/arch/AArch64/module.c
+++ b/arch/AArch64/module.c
@@ -35,7 +35,7 @@
{
}
-static void __attribute__ ((constructor)) __init_arm64__()
+void AArch64_enable(void)
{
arch_init[CS_ARCH_ARM64] = init;
arch_option[CS_ARCH_ARM64] = option;
diff --git a/arch/ARM/module.c b/arch/ARM/module.c
index 3a46f46..f4307db 100644
--- a/arch/ARM/module.c
+++ b/arch/ARM/module.c
@@ -7,8 +7,6 @@
#include "ARMInstPrinter.h"
#include "mapping.h"
-void enable_arm() {};
-
static cs_err init(cs_struct *ud)
{
MCRegisterInfo *mri = cs_mem_malloc(sizeof(*mri));
@@ -48,7 +46,7 @@
{
}
-static void __attribute__ ((constructor)) __init_arm__()
+void ARM_enable(void)
{
arch_init[CS_ARCH_ARM] = init;
arch_option[CS_ARCH_ARM] = option;
diff --git a/arch/Mips/module.c b/arch/Mips/module.c
index d5030bf..1b16108 100644
--- a/arch/Mips/module.c
+++ b/arch/Mips/module.c
@@ -46,7 +46,7 @@
{
}
-static void __attribute__ ((constructor)) __init_mips__()
+void Mips_enable(void)
{
arch_init[CS_ARCH_MIPS] = init;
arch_option[CS_ARCH_MIPS] = option;
diff --git a/arch/PowerPC/module.c b/arch/PowerPC/module.c
index 6257d21..2af9d0d 100644
--- a/arch/PowerPC/module.c
+++ b/arch/PowerPC/module.c
@@ -39,7 +39,7 @@
{
}
-static void __attribute__ ((constructor)) __init_mips__()
+void PPC_enable(void)
{
arch_init[CS_ARCH_PPC] = init;
arch_option[CS_ARCH_PPC] = option;
diff --git a/arch/X86/module.c b/arch/X86/module.c
index cd9d1c2..05c0746 100644
--- a/arch/X86/module.c
+++ b/arch/X86/module.c
@@ -50,7 +50,7 @@
{
}
-static void __attribute__ ((constructor)) __init_x86__()
+void X86_enable(void)
{
arch_init[CS_ARCH_X86] = init;
arch_option[CS_ARCH_X86] = option;
diff --git a/cs.c b/cs.c
index bcfcfd2..ce3d7bf 100644
--- a/cs.c
+++ b/cs.c
@@ -14,30 +14,36 @@
cs_err (*arch_option[MAX_ARCH]) (cs_struct *, cs_opt_type, size_t value) = { NULL };
void (*arch_destroy[MAX_ARCH]) (cs_struct *) = { NULL };
-// we need this trick to enable module constructors in static lib
-extern void enable_arm();
-extern void enable_arm64();
-extern void enable_mips();
-extern void enable_x86();
-extern void enable_powerpc();
+extern void ARM_enable(void);
+extern void AArch64_enable(void);
+extern void Mips_enable(void);
+extern void X86_enable(void);
+extern void PPC_enable(void);
-void enable_construct()
+static void archs_enable(void)
{
+ static bool initialized = false;
+
+ if (initialized)
+ return;
+
#ifdef CAPSTONE_HAS_ARM
- enable_arm();
+ ARM_enable();
#endif
#ifdef CAPSTONE_HAS_ARM64
- enable_arm64();
+ AArch64_enable();
#endif
#ifdef CAPSTONE_HAS_MIPS
- enable_mips();
+ Mips_enable();
#endif
#ifdef CAPSTONE_HAS_X86
- enable_x86();
+ X86_enable();
#endif
#ifdef CAPSTONE_HAS_POWERPC
- enable_powerpc();
+ PPC_enable();
#endif
+
+ initialized = true;
}
unsigned int all_arch = 0;
@@ -119,6 +125,8 @@
// with cs_option(CS_OPT_MEM)
return CS_ERR_MEMSETUP;
+ archs_enable();
+
if (arch < CS_ARCH_MAX && arch_init[arch]) {
cs_struct *ud;