Skip to content

Commit

Permalink
Fix: bug that static link does not know constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
danghvu committed Jan 9, 2014
1 parent 5696d98 commit 701b850
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,36 @@ LIBOBJ =
LIBOBJ += cs.o utils.o SStream.o MCInstrDesc.o MCRegisterInfo.o

ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_POWERPC
LIBOBJ += arch/PowerPC/PPCDisassembler.o
LIBOBJ += arch/PowerPC/PPCInstPrinter.o
LIBOBJ += arch/PowerPC/mapping.o
LIBOBJ += arch/PowerPC/module.o
endif
ifneq (,$(findstring arm,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_ARM
LIBOBJ += arch/ARM/ARMDisassembler.o
LIBOBJ += arch/ARM/ARMInstPrinter.o
LIBOBJ += arch/ARM/mapping.o
LIBOBJ += arch/ARM/module.o
endif
ifneq (,$(findstring x86,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_X86
LIBOBJ += arch/X86/X86DisassemblerDecoder.o
LIBOBJ += arch/X86/X86Disassembler.o
LIBOBJ += arch/X86/X86IntelInstPrinter.o
LIBOBJ += arch/X86/X86ATTInstPrinter.o
LIBOBJ += arch/X86/mapping.o arch/X86/module.o
endif
ifneq (,$(findstring mips,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_MIPS
LIBOBJ += arch/Mips/MipsDisassembler.o
LIBOBJ += arch/Mips/MipsInstPrinter.o
LIBOBJ += arch/Mips/mapping.o
LIBOBJ += arch/Mips/module.o
endif
ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_ARM64
LIBOBJ += arch/AArch64/AArch64BaseInfo.o
LIBOBJ += arch/AArch64/AArch64Disassembler.o
LIBOBJ += arch/AArch64/AArch64InstPrinter.o
Expand Down
1 change: 1 addition & 0 deletions arch/AArch64/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "AArch64InstPrinter.h"
#include "mapping.h"

void enable_arm64() {}

static cs_err init(cs_struct *ud)
{
Expand Down
1 change: 1 addition & 0 deletions arch/ARM/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ARMInstPrinter.h"
#include "mapping.h"

void enable_arm() {};

static cs_err init(cs_struct *ud)
{
Expand Down
1 change: 1 addition & 0 deletions arch/Mips/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "MipsInstPrinter.h"
#include "mapping.h"

void enable_mips() {};

static cs_err init(cs_struct *ud)
{
Expand Down
1 change: 1 addition & 0 deletions arch/PowerPC/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "PPCInstPrinter.h"
#include "mapping.h"

void enable_powerpc() {};

static cs_err init(cs_struct *ud)
{
Expand Down
2 changes: 2 additions & 0 deletions arch/X86/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "X86InstPrinter.h"
#include "mapping.h"

void enable_x86() {};

static cs_err init(cs_struct *ud)
{
// by default, we use Intel syntax
Expand Down
23 changes: 23 additions & 0 deletions cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ cs_err (*arch_init[MAX_ARCH])(cs_struct *) = { NULL };
cs_err (*arch_option[MAX_ARCH]) (cs_struct *, cs_opt_type, size_t value) = { NULL };
void (*arch_destroy[MAX_ARCH]) (cs_struct *) = { NULL };

extern void enable_arm();
extern void enable_arm64();
extern void enable_mips();
extern void enable_x86();
extern void enable_powerpc();

unsigned int all_arch = 0;

#ifdef USE_SYS_DYN_MEM
Expand Down Expand Up @@ -84,8 +90,25 @@ const char *cs_strerror(cs_err code)
}
}

void enable_construct() {
enable_arm();
#ifdef CAPSTONE_HAS_ARM64
enable_arm64();
#endif
#ifdef CAPSTONE_HAS_MIPS
enable_mips();
#endif
#ifdef CAPSTONE_HAS_X86
enable_x86();
#endif
#ifdef CAPSTONE_HAS_POWERPC
enable_powerpc();
#endif
}

cs_err cs_open(cs_arch arch, cs_mode mode, csh *handle)
{
enable_construct();
if (!my_malloc || !my_calloc || !my_realloc || !my_free)
// Error: before cs_open(), dynamic memory management must be initialized
// with cs_option(CS_OPT_MEM)
Expand Down

0 comments on commit 701b850

Please sign in to comment.