From ac584a4c61259908bf5c047691137f51f71faa95 Mon Sep 17 00:00:00 2001 From: midipix Date: Feb 25 2019 06:27:37 +0000 Subject: project: static linking: dlfake: initial commit. --- diff --git a/project/extras.mk b/project/extras.mk index 12fe21f..978dc74 100644 --- a/project/extras.mk +++ b/project/extras.mk @@ -23,6 +23,13 @@ LDFLAGS_CONFIG += -Wl,-rpath -Wl,$(LIBDIR) ifeq ($(ALL_STATIC),yes) CFLAGS_STATIC += -DPY_ALL_STATIC + CFLAGS_STATIC += -I$(PROJECT_DIR)/wrappers/dlfcn + CFLAGS_STATIC += --include=dlfake.h + + DLFAKE_SRCS += $(PROJECT_DIR)/wrappers/dlfcn/dlfake.c + DLFAKE_OBJS += core/Objects/dlfake.o + STATIC_OBJS += $(DLFAKE_OBJS) + LDFLAGS_STATIC += $(PYEXT_STATIC) LDFLAGS_STATIC += $(LDFLAGS_PYEXT_STATIC) @@ -38,6 +45,10 @@ else CFLAGS_CONFIG += -DHAVE_DYNAMIC_LOADING -DSOABI=\"$(PYTHON_SOABI)\" endif +# dlfake +core/Objects/dlfake.o: $(DLFAKE_SRCS) $(ALL_HEADERS) host.tag tree.tag config.tag + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + # extension objects pyext/obj/%.lo: $(SOURCE_DIR)/Modules/%.c $(ALL_HEADERS) host.tag tree.tag config.tag $(CC) -c -o $@ $< $(CFLAGS_SHARED) diff --git a/project/headers.mk b/project/headers.mk index a275e50..7078ecf 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -1,3 +1,5 @@ ifneq ($(PYTHON_MAJOR),) include $(PROJECT_DIR)/project/variants/$(PYTHON_MAJOR).$(PYTHON_MINOR).$(PYTHON_MICRO)/headers.mk endif + +INTERNAL_HEADERS += $(PROJECT_DIR)/wrappers/dlfcn/dlfake.h diff --git a/wrappers/dlfcn/dlfake.c b/wrappers/dlfcn/dlfake.c new file mode 100644 index 0000000..d347bf0 --- /dev/null +++ b/wrappers/dlfcn/dlfake.c @@ -0,0 +1,42 @@ +#include "dlfake.h" +#include "linkage/inittab.h" + +extern struct _inittab _PyImport_Inittab[]; + +void * dlfake_dlopen(const char * name, int mode) +{ + struct _inittab * pyext; + + if (!name) + return _PyImport_Inittab; + + for (pyext=_PyImport_Inittab; pyext->name; pyext++) + if (!strcmp(name,pyext->name)) + return _PyImport_Inittab; + + return 0; +} + +int dlfake_dlclose(void * handle) +{ + return -1; +} + +void * dlfake_dlsym(void * handle, const char * sym) +{ + return 0; +} + +static const char dlfake_errstr[] = + "dlfake_dlerror(): " + "not implemented"; + +char * dlfake_dlerror(void) +{ + return (char *)dlfake_errstr; +} + +int dlfake_dladdr(const void * addr, void * info) +{ + return 0; +} diff --git a/wrappers/dlfcn/dlfake.h b/wrappers/dlfcn/dlfake.h new file mode 100644 index 0000000..87ccab7 --- /dev/null +++ b/wrappers/dlfcn/dlfake.h @@ -0,0 +1,30 @@ +#ifndef _CTYPES_DLFCN_H_ +#define _CTYPES_DLFCN_H_ + +#ifndef PY_ALL_STATIC +#error something went wrong +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void * dlfake_dlopen(const char *, int); +int dlfake_dlclose(void *); +void * dlfake_dlsym(void *, const char *); +char * dlfake_dlerror(void); +int dlfake_dladdr(const void *, void *); + +#define ctypes_dlopen dlfake_dlopen +#define ctypes_dlclose dlfake_dlclose +#define ctypes_dlsym dlfake_dlsym +#define ctypes_dladdr dlfake_dladdr +#define ctypes_dlerror dlfake_dlerror + +#ifdef __cplusplus +} +#endif + +#endif