From a7dddf6c5f131f418d3d408c1213157bb689c584 Mon Sep 17 00:00:00 2001 From: Antoine Date: Fri, 23 Dec 2016 16:59:19 +0000 Subject: [PATCH 1/5] python bindings: restore FreeBSD support (#698) * python bindings: restore FreeBSD support * python binding: use libunicorn.so if the platform is unknown --- bindings/python/unicorn/unicorn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 549aa8ea..097bbef1 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -62,7 +62,7 @@ def _load_lib(path): if sys.platform in ('win32', 'cygwin'): _load_win_support(path) - lib_file = os.path.join(path, _lib[sys.platform]) + lib_file = os.path.join(path, _lib.get(sys.platform, 'libunicorn.so')) #print('Trying to load shared library', lib_file) dll = ctypes.cdll.LoadLibrary(lib_file) #print('SUCCESS') From 06541894ea6dc2f187ffb7c63e40bb687e6e56e7 Mon Sep 17 00:00:00 2001 From: danghvu Date: Sun, 25 Dec 2016 21:46:52 -0600 Subject: [PATCH 2/5] Makefile: uc.o and list.o is compiled with qemu, fix for issue #696 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8c9d60e6..70d0e866 100644 --- a/Makefile +++ b/Makefile @@ -210,7 +210,7 @@ qemu/config-host.h-timestamp: unicorn: $(LIBRARY) $(ARCHIVE) -$(LIBRARY): qemu/config-host.h-timestamp uc.o list.o +$(LIBRARY): qemu/config-host.h-timestamp ifeq ($(UNICORN_SHARED),yes) ifeq ($(V),0) $(call log,GEN,$(LIBRARY)) @@ -222,7 +222,7 @@ else endif endif -$(ARCHIVE): qemu/config-host.h-timestamp uc.o list.o +$(ARCHIVE): qemu/config-host.h-timestamp ifeq ($(UNICORN_STATIC),yes) ifeq ($(V),0) $(call log,GEN,$(ARCHIVE)) From e9b8968a23b3ab8b6e380d681b024b5ebb24c2de Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Mon, 26 Dec 2016 13:12:15 +0800 Subject: [PATCH 3/5] Update install-cmocka-linux.sh temporarily fix the cmocka download issue by avoid using https --- install-cmocka-linux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-cmocka-linux.sh b/install-cmocka-linux.sh index 46b405a4..0c6eda79 100755 --- a/install-cmocka-linux.sh +++ b/install-cmocka-linux.sh @@ -1,7 +1,7 @@ #!/bin/sh set -ex mkdir cmocka -wget https://cmocka.org/files/1.1/cmocka-1.1.0.tar.xz -O /tmp/cmocka-1.1.0.tar.xz +wget --no-check-certificate http://cmocka.org/files/1.1/cmocka-1.1.0.tar.xz -O /tmp/cmocka-1.1.0.tar.xz tar -xf /tmp/cmocka-1.1.0.tar.xz -C /tmp cd cmocka && cmake -DUNIT_TESTING=On /tmp/cmocka-1.1.0 && make && make test # cmake builds an so instead of a dll in mingw/msys From 8a9a5432c37d8a65777262d832ea14116c488904 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Mon, 26 Dec 2016 13:45:40 +0800 Subject: [PATCH 4/5] add back as a comment the https download for cmocka to install-cmocka-linux.sh --- install-cmocka-linux.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install-cmocka-linux.sh b/install-cmocka-linux.sh index 0c6eda79..a9530ac2 100755 --- a/install-cmocka-linux.sh +++ b/install-cmocka-linux.sh @@ -1,6 +1,7 @@ #!/bin/sh set -ex mkdir cmocka +#wget https://cmocka.org/files/1.1/cmocka-1.1.0.tar.xz -O /tmp/cmocka-1.1.0.tar.xz wget --no-check-certificate http://cmocka.org/files/1.1/cmocka-1.1.0.tar.xz -O /tmp/cmocka-1.1.0.tar.xz tar -xf /tmp/cmocka-1.1.0.tar.xz -C /tmp cd cmocka && cmake -DUNIT_TESTING=On /tmp/cmocka-1.1.0 && make && make test From bf2cd79a4da8522faca6dad5b5f2eec55ccffe70 Mon Sep 17 00:00:00 2001 From: Andrew Dutcher Date: Tue, 27 Dec 2016 00:30:07 -0800 Subject: [PATCH 5/5] Windows: export a static lib that can be used outside of mingw (#699) * Windows: export a static lib that can be used outside of mingw * Add comments to windows_export.bat --- .gitignore | 2 ++ Makefile | 13 +++++++++++-- bindings/python/setup.py | 8 ++++++-- samples/Makefile | 2 +- windows_export.bat | 16 ++++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 windows_export.bat diff --git a/.gitignore b/.gitignore index 0c5f8e89..10d73b35 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,8 @@ unicorn.pc unicorn.lib unicorn.dll +unicorn.exp +unicorn.def unicorn_*.lib unicorn_*.exp unicorn_*.dll diff --git a/Makefile b/Makefile index 70d0e866..b105f60c 100644 --- a/Makefile +++ b/Makefile @@ -122,10 +122,12 @@ UNICORN_CFLAGS := $(UNICORN_CFLAGS:-fPIC=) # mingw? else ifneq ($(filter MINGW%,$(UNAME_S)),) EXT = dll -AR_EXT = lib +AR_EXT = a BIN_EXT = .exe UNICORN_QEMU_FLAGS += --disable-stack-protector UNICORN_CFLAGS := $(UNICORN_CFLAGS:-fPIC=) +$(LIBNAME)_LDFLAGS += -Wl,--output-def,unicorn.def +DO_WINDOWS_EXPORT = 1 # Linux, Darwin else @@ -220,6 +222,13 @@ else $(CC) $(CFLAGS) -shared $(UC_TARGET_OBJ) uc.o list.o -o $(LIBRARY) $($(LIBNAME)_LDFLAGS) -ln -sf $(LIBRARY) $(LIBRARY_SYMLINK) endif +ifeq ($(DO_WINDOWS_EXPORT),1) +ifneq ($(filter MINGW32%,$(UNAME_S)),) + cmd /c "windows_export.bat x86" +else + cmd /c "windows_export.bat x64" +endif +endif endif $(ARCHIVE): qemu/config-host.h-timestamp @@ -301,7 +310,7 @@ uninstall: clean: $(MAKE) -C qemu clean rm -rf *.d *.o - rm -rf lib$(LIBNAME)* $(LIBNAME)*.lib $(LIBNAME)*.dll cyg$(LIBNAME)*.dll + rm -rf lib$(LIBNAME)* $(LIBNAME)*.lib $(LIBNAME)*.dll $(LIBNAME)*.exp cyg$(LIBNAME)*.dll $(MAKE) -C samples clean $(MAKE) -C tests/unit clean diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 553e7f14..4951fb6d 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -43,7 +43,7 @@ if SYSTEM == 'darwin': STATIC_LIBRARY_FILE = 'libunicorn.a' elif SYSTEM in ('win32', 'cygwin'): LIBRARY_FILE = "unicorn.dll" - STATIC_LIBRARY_FILE = None + STATIC_LIBRARY_FILE = "unicorn.lib" else: LIBRARY_FILE = "libunicorn.so" STATIC_LIBRARY_FILE = 'libunicorn.a' @@ -147,7 +147,11 @@ def build_libraries(): subprocess.call(cmd, env=new_env) shutil.copy(LIBRARY_FILE, LIBS_DIR) - if STATIC_LIBRARY_FILE: shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR) + try: + # static library may fail to build on windows if user doesn't have visual studio 12 installed. this is fine. + shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR) + except: + pass os.chdir(cwd) diff --git a/samples/Makefile b/samples/Makefile index b556cb00..abb0912a 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -43,7 +43,7 @@ AR_EXT = a else ifneq ($(filter MINGW%,$(UNAME_S)),) CFLAGS := $(CFLAGS:-fPIC=) BIN_EXT = .exe -AR_EXT = lib +AR_EXT = a endif ifeq ($(UNICORN_STATIC),yes) diff --git a/windows_export.bat b/windows_export.bat new file mode 100644 index 00000000..4ff67fba --- /dev/null +++ b/windows_export.bat @@ -0,0 +1,16 @@ +@echo on + +:: This script invokes the visual studio linker to construct a static library file that can be used outside of mingw. +:: The unicorn.def file that it references below is produced by the mingw compiler via a linker flag. +:: The arch (x86 or x64) we are working on should be passed via the first argument to this script. + +:: Look up the Visual Studio install path via the registry +:: http://stackoverflow.com/questions/445167/how-can-i-get-the-value-of-a-registry-key-from-within-a-batch-script +:: If anyone ever tells you that windows is a reasonable operating system, they are wrong +FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0" /v InstallDir`) DO ( + set appdir=%%A %%B +) + +:: Add the visual studio binaries to our path and run the linker +call "%appdir%..\..\VC\vcvarsall.bat" %1 +call lib /machine:%1 /def:unicorn.def