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
2015-03-06 21:58:56 +01:00
parent 52664791f5
commit a74b640507
5 changed files with 68 additions and 19 deletions
+19 -6
View File
@@ -56,6 +56,19 @@ FINIT_FIFO ?= /dev/initctl
FINIT_CONF ?= $(sysconfdir)/finit.conf
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
# Disable annoying gcc warning for "warn_unused_result", see GIT 37af997
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 += -DFINIT_FIFO=\"$(FINIT_FIFO)\" -DFINIT_CONF=\"$(FINIT_CONF)\"
CPPFLAGS += -DFINIT_RCSD=\"$(FINIT_RCSD)\" -DPLUGIN_PATH=\"$(plugindir)\"
LDFLAGS += -rdynamic -L$(TOPDIR)/libite
DEPLIBS = libite/libite.so libuev/libuev.a
LDLIBS += -ldl -lite
LDFLAGS += -L$(TOPDIR)/libite -L$(TOPDIR)/libuev
DEPLIBS = libite/libite.a libuev/libuev.a
LDLIBS += -lite -luev
include common.mk
export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS
export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS STATIC
all: $(DEPLIBS) $(EXEC)
+$(MAKE) -C plugins $@
@@ -78,9 +91,9 @@ $(DEPLIBS): Makefile
+$(MAKE) -C libite all
+$(MAKE) -C libuev all
$(OBJS): Makefile
$(OBJS): Makefile $(DEPLIBS)
finit: $(OBJS) $(DEPLIBS)
finit: $(OBJS)
reboot: reboot.o $(DEPLIBS)
+1
View File
@@ -8,6 +8,7 @@ MAKEFLAGS = --no-print-directory --silent
CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all
INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
ARFLAGS := crus
# Smart autodependecy generation via GCC -M.
.%.d: %.c
+25 -11
View File
@@ -25,7 +25,9 @@
include ../common.mk
ifneq ($(STATIC), 1)
CFLAGS += -fPIC
endif
HEADERS = lite.h
OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o
OBJS += strlcpy.o strlcat.o strtonum.o
@@ -33,9 +35,14 @@ DEPS := $(addprefix ., $(OBJS:.o=.d))
VER = 0
LIBNAME = libite
TARGET = $(LIBNAME).so
VERLIB = $(TARGET).$(VER)
SOLIB = $(LIBNAME).so.$(VER)
SYMLIB = $(LIBNAME).so
STATICLIB = $(LIBNAME).a
ifeq ($(STATIC), 1)
TARGET = $(STATICLIB)
else
TARGET = $(STATICLIB) $(SOLIB)
endif
CHECK_FLAGS = $(CFLAGS) $(CPPFLAGS)
@@ -43,17 +50,20 @@ all: $(TARGET)
$(OBJS): Makefile
$(TARGET): $(OBJS)
$(SOLIB): $(OBJS)
@printf " LINK %s\n" $@
# @$(AR) $(ARFLAGS) $(STATICLIB) $(OBJS)
@$(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 -d $(DESTDIR)$(libdir)
@echo " INSTALL $(DESTDIR)$(libdir)/$(TARGET)"
@$(STRIPINST) $(TARGET) $(DESTDIR)$(libdir)/$(TARGET)
@ln -sf $(TARGET) $(DESTDIR)$(libdir)/$(VERLIB)
@printf " INSTALL $(DESTDIR)$(libdir)/$(SOLIB)\n"
@$(STRIPINST) $(SOLIB) $(DESTDIR)$(libdir)/$(SOLIB)
@$(STRIPINST) $(STATICLIB) $(DESTDIR)$(libdir)/$(STATICLIB)
@ln -sf $(SOLIB) $(DESTDIR)$(libdir)/$(SYMLIB)
install-dev:
@for file in $(HEADERS); do \
@@ -61,11 +71,15 @@ install-dev:
$(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$$file; \
done
install: install-dev install-exec
install: install-exec install-dev
uninstall:
-@$(RM) $(DESTDIR)$(libdir)/$(VERLIB)
-@$(RM) $(DESTDIR)$(libdir)/$(TARGET)
-@$(RM) $(DESTDIR)$(libdir)/$(SOLIB)
-@$(RM) $(DESTDIR)$(libdir)/$(SYMLIB)
-@$(RM) $(DESTDIR)$(libdir)/$(STATICLIB)
-@for file in $(HEADERS); do \
$(RM) $(DESTDIR)$(incdir)/$$file; \
done
clean: uninstall
-@$(RM) $(OBJS) $(DEPS) $(TARGET) $(VERLIB) $(STATICLIB)
+20 -1
View File
@@ -39,7 +39,9 @@
static char *plugpath = NULL; /* Set by first load. */
static TAILQ_HEAD(plugin_head, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins);
#ifndef PLUGINS_STATIC
static void check_plugin_depends(plugin_t *plugin);
#endif
int plugin_register(plugin_t *plugin)
{
@@ -50,12 +52,16 @@ int plugin_register(plugin_t *plugin)
/* Setup default name if none is provided */
if (!plugin->name) {
#ifndef PLUGINS_STATIC
Dl_info info;
if (!dladdr(plugin, &info) || !info.dli_fname)
plugin->name = "unknown";
else
plugin->name = (char *)info.dli_fname;
#else
plugin->name = "unknown";
#endif
}
/* Already registered? */
@@ -64,8 +70,10 @@ int plugin_register(plugin_t *plugin)
return 0;
}
#ifndef PLUGINS_STATIC
/* Resolve plugin dependencies */
check_plugin_depends(plugin);
#endif
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. */
int plugin_unregister(plugin_t *plugin)
{
#ifndef PLUGINS_STATIC
TAILQ_REMOVE(&plugins, plugin, link);
if (plugin->svc.cb) {
@@ -92,6 +101,9 @@ int plugin_unregister(plugin_t *plugin)
_e("Failed unloading %s ...", plugin->name);
return 1;
}
#else
_d("Finit built statically, cannot unload %s ...", plugin->name);
#endif
return 0;
}
@@ -191,7 +203,7 @@ static void init_plugins(uev_ctx_t *ctx)
}
}
#ifndef PLUGINS_STATIC
/**
* load_one - Load one plugin
* @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]);
}
}
#endif /* PLUGINS_STATIC */
int plugin_load_all(uev_ctx_t *ctx, char *path)
{
int fail = 0;
#ifndef PLUGINS_STATIC
DIR *dp = opendir(path);
struct dirent *entry;
@@ -295,6 +309,11 @@ int plugin_load_all(uev_ctx_t *ctx, char *path)
}
closedir(dp);
#else
_d("Finit built statically, not loading plugins from %s ...", path);
#endif /* PLUGINS_STATIC */
/* Always initialize plugins */
init_plugins(ctx);
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
CPPFLAGS += -I..
LDFLAGS := $(filter-out -rdynamic, $(LDFLAGS))
LDFLAGS += -shared
ifneq ($(STATIC), 1)
PLUGINS ?= initctl.so alsa-utils.so bootmisc.so dbus.so hwclock.so \
resolvconf.so urandom.so x11-common.so tty.so time.so
DEPS = $(addprefix .,$(PLUGINS:.so=.d))
endif
TOPDIR ?= $(shell pwd)
include ../common.mk