Initial support for building Finit statically (incomplete)

This patch adresses issue #5.  However, there still remains a few issues
to work around before Finit can be built completely standalone.

    $ make clean all STATIC=1
    LINK    finit
    helpers.o: In function `getgroup':
    helpers.c:(.text+0x10a7): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    helpers.o: In function `getuser':
    helpers.c:(.text+0x108e): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    inetd.o: In function `getent':
    inetd.c:(.text+0x127): warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    inetd.c:(.text+0xce): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

The problem is the NSS plugins and similar issues that prevent static
linking when using the above functions.  See issue #5 for more on this.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2015-03-06 21:58:56 +01:00
1 parent 52664791f5
commit a74b640507
5 files changed
+68 -19

No files matched your search

+19 -6
View File
@@ -56,6 +56,19 @@ FINIT_FIFO ?= /dev/initctl
FINIT_CONF ?= $(sysconfdir)/finit.conf FINIT_CONF ?= $(sysconfdir)/finit.conf
FINIT_RCSD ?= $(sysconfdir)/finit.d FINIT_RCSD ?= $(sysconfdir)/finit.d
# Some people may want to build Finit with statically linked libraries
# invocation: make STATIC=1
ifeq ($(STATIC), 1)
LDFLAGS += -static
CPPFLAGS += -DPLUGINS_STATIC
PLUGINS = ""
SRCS += $(wjldcard plugins/*.c)
OBJS := $(SRCS:.c=.o)
else
LDFLAGS += -rdynamic
LDLIBS += -ldl
endif
CFLAGS += -W -Wall -Werror -Os CFLAGS += -W -Wall -Werror -Os
# Disable annoying gcc warning for "warn_unused_result", see GIT 37af997 # Disable annoying gcc warning for "warn_unused_result", see GIT 37af997
CPPFLAGS += -U_FORTIFY_SOURCE CPPFLAGS += -U_FORTIFY_SOURCE
@@ -64,12 +77,12 @@ CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\" CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\"
CPPFLAGS += -DFINIT_FIFO=\"$(FINIT_FIFO)\" -DFINIT_CONF=\"$(FINIT_CONF)\" CPPFLAGS += -DFINIT_FIFO=\"$(FINIT_FIFO)\" -DFINIT_CONF=\"$(FINIT_CONF)\"
CPPFLAGS += -DFINIT_RCSD=\"$(FINIT_RCSD)\" -DPLUGIN_PATH=\"$(plugindir)\" CPPFLAGS += -DFINIT_RCSD=\"$(FINIT_RCSD)\" -DPLUGIN_PATH=\"$(plugindir)\"
LDFLAGS += -rdynamic -L$(TOPDIR)/libite LDFLAGS += -L$(TOPDIR)/libite -L$(TOPDIR)/libuev
DEPLIBS = libite/libite.so libuev/libuev.a DEPLIBS = libite/libite.a libuev/libuev.a
LDLIBS += -ldl -lite LDLIBS += -lite -luev
include common.mk include common.mk
export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS STATIC
all: $(DEPLIBS) $(EXEC) all: $(DEPLIBS) $(EXEC)
+$(MAKE) -C plugins $@ +$(MAKE) -C plugins $@
@@ -78,9 +91,9 @@ $(DEPLIBS): Makefile
+$(MAKE) -C libite all +$(MAKE) -C libite all
+$(MAKE) -C libuev all +$(MAKE) -C libuev all
$(OBJS): Makefile $(OBJS): Makefile $(DEPLIBS)
finit: $(OBJS) $(DEPLIBS) finit: $(OBJS)
reboot: reboot.o $(DEPLIBS) reboot: reboot.o $(DEPLIBS)
+1
View File
@@ -8,6 +8,7 @@ MAKEFLAGS = --no-print-directory --silent
CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all
INSTALL := install --backup=off INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755 STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
ARFLAGS := crus
# Smart autodependecy generation via GCC -M. # Smart autodependecy generation via GCC -M.
.%.d: %.c .%.d: %.c
+25 -11
View File
@@ -25,7 +25,9 @@
include ../common.mk include ../common.mk
ifneq ($(STATIC), 1)
CFLAGS += -fPIC CFLAGS += -fPIC
endif
HEADERS = lite.h HEADERS = lite.h
OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o
OBJS += strlcpy.o strlcat.o strtonum.o OBJS += strlcpy.o strlcat.o strtonum.o
@@ -33,9 +35,14 @@ DEPS := $(addprefix ., $(OBJS:.o=.d))
VER = 0 VER = 0
LIBNAME = libite LIBNAME = libite
TARGET = $(LIBNAME).so SOLIB = $(LIBNAME).so.$(VER)
VERLIB = $(TARGET).$(VER) SYMLIB = $(LIBNAME).so
STATICLIB = $(LIBNAME).a STATICLIB = $(LIBNAME).a
ifeq ($(STATIC), 1)
TARGET = $(STATICLIB)
else
TARGET = $(STATICLIB) $(SOLIB)
endif
CHECK_FLAGS = $(CFLAGS) $(CPPFLAGS) CHECK_FLAGS = $(CFLAGS) $(CPPFLAGS)
@@ -43,17 +50,20 @@ all: $(TARGET)
$(OBJS): Makefile $(OBJS): Makefile
$(TARGET): $(OBJS) $(SOLIB): $(OBJS)
@printf " LINK %s\n" $@ @printf " LINK %s\n" $@
# @$(AR) $(ARFLAGS) $(STATICLIB) $(OBJS)
@$(CC) $(LDFLAGS) -shared $(OBJS) -lrt -lcrypt -Wl,-soname,$@ -o $@ @$(CC) $(LDFLAGS) -shared $(OBJS) -lrt -lcrypt -Wl,-soname,$@ -o $@
@ln -sf $@ $(VERLIB)
$(STATICLIB): Makefile $(OBJS)
@printf " ARCHIVE $@\n"
@$(AR) $(ARFLAGS) $@ $(OBJS)
install-exec: all install-exec: all
@install -d $(DESTDIR)$(libdir) @install -d $(DESTDIR)$(libdir)
@echo " INSTALL $(DESTDIR)$(libdir)/$(TARGET)" @printf " INSTALL $(DESTDIR)$(libdir)/$(SOLIB)\n"
@$(STRIPINST) $(TARGET) $(DESTDIR)$(libdir)/$(TARGET) @$(STRIPINST) $(SOLIB) $(DESTDIR)$(libdir)/$(SOLIB)
@ln -sf $(TARGET) $(DESTDIR)$(libdir)/$(VERLIB) @$(STRIPINST) $(STATICLIB) $(DESTDIR)$(libdir)/$(STATICLIB)
@ln -sf $(SOLIB) $(DESTDIR)$(libdir)/$(SYMLIB)
install-dev: install-dev:
@for file in $(HEADERS); do \ @for file in $(HEADERS); do \
@@ -61,11 +71,15 @@ install-dev:
$(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$$file; \ $(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$$file; \
done done
install: install-dev install-exec install: install-exec install-dev
uninstall: uninstall:
-@$(RM) $(DESTDIR)$(libdir)/$(VERLIB) -@$(RM) $(DESTDIR)$(libdir)/$(SOLIB)
-@$(RM) $(DESTDIR)$(libdir)/$(TARGET) -@$(RM) $(DESTDIR)$(libdir)/$(SYMLIB)
-@$(RM) $(DESTDIR)$(libdir)/$(STATICLIB)
-@for file in $(HEADERS); do \
$(RM) $(DESTDIR)$(incdir)/$$file; \
done
clean: uninstall clean: uninstall
-@$(RM) $(OBJS) $(DEPS) $(TARGET) $(VERLIB) $(STATICLIB) -@$(RM) $(OBJS) $(DEPS) $(TARGET) $(VERLIB) $(STATICLIB)
+20 -1
View File
@@ -39,7 +39,9 @@
static char *plugpath = NULL; /* Set by first load. */ static char *plugpath = NULL; /* Set by first load. */
static TAILQ_HEAD(plugin_head, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins); static TAILQ_HEAD(plugin_head, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins);
#ifndef PLUGINS_STATIC
static void check_plugin_depends(plugin_t *plugin); static void check_plugin_depends(plugin_t *plugin);
#endif
int plugin_register(plugin_t *plugin) int plugin_register(plugin_t *plugin)
{ {
@@ -50,12 +52,16 @@ int plugin_register(plugin_t *plugin)
/* Setup default name if none is provided */ /* Setup default name if none is provided */
if (!plugin->name) { if (!plugin->name) {
#ifndef PLUGINS_STATIC
Dl_info info; Dl_info info;
if (!dladdr(plugin, &info) || !info.dli_fname) if (!dladdr(plugin, &info) || !info.dli_fname)
plugin->name = "unknown"; plugin->name = "unknown";
else else
plugin->name = (char *)info.dli_fname; plugin->name = (char *)info.dli_fname;
#else
plugin->name = "unknown";
#endif
} }
/* Already registered? */ /* Already registered? */
@@ -64,8 +70,10 @@ int plugin_register(plugin_t *plugin)
return 0; return 0;
} }
#ifndef PLUGINS_STATIC
/* Resolve plugin dependencies */ /* Resolve plugin dependencies */
check_plugin_depends(plugin); check_plugin_depends(plugin);
#endif
TAILQ_INSERT_TAIL(&plugins, plugin, link); TAILQ_INSERT_TAIL(&plugins, plugin, link);
@@ -75,6 +83,7 @@ int plugin_register(plugin_t *plugin)
/* Not called, at the moment plugins cannot be unloaded. */ /* Not called, at the moment plugins cannot be unloaded. */
int plugin_unregister(plugin_t *plugin) int plugin_unregister(plugin_t *plugin)
{ {
#ifndef PLUGINS_STATIC
TAILQ_REMOVE(&plugins, plugin, link); TAILQ_REMOVE(&plugins, plugin, link);
if (plugin->svc.cb) { if (plugin->svc.cb) {
@@ -92,6 +101,9 @@ int plugin_unregister(plugin_t *plugin)
_e("Failed unloading %s ...", plugin->name); _e("Failed unloading %s ...", plugin->name);
return 1; return 1;
} }
#else
_d("Finit built statically, cannot unload %s ...", plugin->name);
#endif
return 0; return 0;
} }
@@ -191,7 +203,7 @@ static void init_plugins(uev_ctx_t *ctx)
} }
} }
#ifndef PLUGINS_STATIC
/** /**
* load_one - Load one plugin * load_one - Load one plugin
* @path: Path to finit plugins, usually %PLUGIN_PATH * @path: Path to finit plugins, usually %PLUGIN_PATH
@@ -270,10 +282,12 @@ static void check_plugin_depends(plugin_t *plugin)
load_one(plugpath, plugin->depends[i]); load_one(plugpath, plugin->depends[i]);
} }
} }
#endif /* PLUGINS_STATIC */
int plugin_load_all(uev_ctx_t *ctx, char *path) int plugin_load_all(uev_ctx_t *ctx, char *path)
{ {
int fail = 0; int fail = 0;
#ifndef PLUGINS_STATIC
DIR *dp = opendir(path); DIR *dp = opendir(path);
struct dirent *entry; struct dirent *entry;
@@ -295,6 +309,11 @@ int plugin_load_all(uev_ctx_t *ctx, char *path)
} }
closedir(dp); closedir(dp);
#else
_d("Finit built statically, not loading plugins from %s ...", path);
#endif /* PLUGINS_STATIC */
/* Always initialize plugins */
init_plugins(ctx); init_plugins(ctx);
return fail; return fail;
+3 -1
View File
@@ -1,11 +1,13 @@
# Plugin based services architecture for finit -*-Makefile-*- # Plugin based services architecture for finit
CFLAGS += -fPIC -Os CFLAGS += -fPIC -Os
CPPFLAGS += -I.. CPPFLAGS += -I..
LDFLAGS := $(filter-out -rdynamic, $(LDFLAGS)) LDFLAGS := $(filter-out -rdynamic, $(LDFLAGS))
LDFLAGS += -shared LDFLAGS += -shared
ifneq ($(STATIC), 1)
PLUGINS ?= initctl.so alsa-utils.so bootmisc.so dbus.so hwclock.so \ PLUGINS ?= initctl.so alsa-utils.so bootmisc.so dbus.so hwclock.so \
resolvconf.so urandom.so x11-common.so tty.so time.so resolvconf.so urandom.so x11-common.so tty.so time.so
DEPS = $(addprefix .,$(PLUGINS:.so=.d)) DEPS = $(addprefix .,$(PLUGINS:.so=.d))
endif
TOPDIR ?= $(shell pwd) TOPDIR ?= $(shell pwd)
include ../common.mk include ../common.mk