Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
static linking of modules
- X-seq: zsh-workers 2455
- From: Zefram <zefram@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Z Shell workers mailing list)
- Subject: static linking of modules
- Date: Fri, 22 Nov 1996 17:41:37 +0000 (GMT)
-----BEGIN PGP SIGNED MESSAGE-----
This patch implements compiling modules into the main zsh executable.
This should work even where dynamic module loading is impossible, so
now even our poor deprived SunOS-using brethren can benefit from the
example builtin.
The Makefile magic is controlled by a file `modules-bltin' in the source
directory, which is a whitespace-separated list of names of modules
that are to be compiled in. This patch creates it containing the line
"example", for demonstration purposes, but the default should probably
be empty in proper distributions.
- From modules-bltin, the Makefile creates stamp-modobjs, a combined
timestamp and list of extra object files. (Concept borrowed from GCC.)
It modifies stamp-modobjs each time any of the objects changes, and
each time its contents must change. The Makefile also generates
bltinmods.list, a simple transformation of modules-bltin that is
convenient to #include into C source. It is used in the new function,
in init.c, that boots all the compiled-in modules.
I changed the variable module boot function name to a fixed scheme,
which is much simpler and makes modules work independently of filename.
When modules are being compiled normally (to be compiled into zsh),
the fixed names are #defined to appropriate variable names, in order
to allow multiple modules to be compiled in simultaneously. There is a
complication with this: the easiest way to do it was a messy backquoted
sed in the standard compilation rules. It would be nice to avoid this
overhead for the majority of objects that have nothing to do with modules.
The modules that are compiled in can also be compiled as separate modules
at the same time, and in fact that's what will happen unless the Makefile
is modified. It might be nice for the modules rule to avoid building
modules mentioned in modules-bltin, but there are advantages in building
all the modules anyway.
-zefram
Index: Src/Makefile.in
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/Makefile.in,v
retrieving revision 1.7
diff -c -r1.7 Makefile.in
*** Makefile.in 1996/11/21 01:29:25 1.7
--- Makefile.in 1996/11/22 01:41:37
***************
*** 52,58 ****
DLLDFLAGS = @DLLDFLAGS@
EXTRA_LDFLAGS = @EXTRA_LDFLAGS@
! INCLUDES = -I.. -I. -I$(srcdir)
DNCFLAGS =
--- 52,58 ----
DLLDFLAGS = @DLLDFLAGS@
EXTRA_LDFLAGS = @EXTRA_LDFLAGS@
! INCLUDES = -I.. -I. -I$(srcdir) -I$(MODULE_DIR)
DNCFLAGS =
***************
*** 67,72 ****
--- 67,80 ----
AWK = @AWK@
SED = sed
+ # flags passed to recursive makes
+ MAKEDEFS = CC='$(CC)' CPPFLAGS='$(CPPFLAGS)' DEFS='$(DEFS)' \
+ CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' LIBS='$(LIBS)' \
+ prefix='$(prefix)' exec_prefix='$(exec_prefix)' bindir='$(bindir)' \
+ infodir='$(infodir)' mandir='$(mandir)' manext='$(manext)'
+
+ MODBINS = $(srcdir)/modules-bltin
+
DLEXT=.$(DL_EXT)
NLEXT=._foobarbaz_
***************
*** 82,107 ****
ANSIDOBJ=$(@D@LEXT)
ANSI_DOBJ=._bar_
.SUFFIXES:
.SUFFIXES: .c $(ANSI@U@DOBJ) $(KNR@U@DOBJ) $(ANSI@U@OBJ) $(KNR@U@OBJ) .pro
.c$(ANSI@U@DOBJ):
! $(COMPILE) $(DLCFLAGS) -I$(MODULE_DIR) -o $@.o $<
$(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $@ $@.o
rm -f $@.o
.c$(KNR@U@DOBJ):
./ansi2knr $< > $@.c
! $(COMPILE) $(DLCFLAGS) -I$(MODULE_DIR) -o $@.o $@.c
$(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $@ $@.o
rm -f $@.[oc]
.c$(ANSI@U@OBJ):
! $(COMPILE) $<
.c$(KNR@U@OBJ): ansi2knr
./ansi2knr $< > $@.c
! $(COMPILE) -o $@ $@.c
rm -f $@.c
.c.pro:
--- 90,121 ----
ANSIDOBJ=$(@D@LEXT)
ANSI_DOBJ=._bar_
+ MODNAMEDEFS = `echo $@ | $(SED) 's,.*/,,;s,\([^.]*\)\..*,-Dmod_boot=mod_boot_\1 -Dmod_cleanup=mod_cleanup_\1,'`
+
.SUFFIXES:
+ .SUFFIXES: .force
.SUFFIXES: .c $(ANSI@U@DOBJ) $(KNR@U@DOBJ) $(ANSI@U@OBJ) $(KNR@U@OBJ) .pro
+ .force:
+ @:
+
.c$(ANSI@U@DOBJ):
! $(COMPILE) $(DLCFLAGS) -o $@.o $<
$(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $@ $@.o
rm -f $@.o
.c$(KNR@U@DOBJ):
./ansi2knr $< > $@.c
! $(COMPILE) $(DLCFLAGS) -o $@.o $@.c
$(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $@ $@.o
rm -f $@.[oc]
.c$(ANSI@U@OBJ):
! $(COMPILE) $(MODNAMEDEFS) -o $@ $<
.c$(KNR@U@OBJ): ansi2knr
./ansi2knr $< > $@.c
! $(COMPILE) $(MODNAMEDEFS) -o $@ $@.c
rm -f $@.c
.c.pro:
***************
*** 138,144 ****
main.pro math.pro mem.pro params.pro parse.pro signals.pro subst.pro \
text.pro utils.pro watch.pro zle_bindings.pro zle_hist.pro zle_main.pro \
zle_misc.pro zle_move.pro zle_refresh.pro zle_tricky.pro zle_utils.pro \
! zle_vi.pro zle_word.pro $(@D@YNAMIC_PROTO)
# object files
DYNAMIC_OBJS = module.o
--- 152,159 ----
main.pro math.pro mem.pro params.pro parse.pro signals.pro subst.pro \
text.pro utils.pro watch.pro zle_bindings.pro zle_hist.pro zle_main.pro \
zle_misc.pro zle_move.pro zle_refresh.pro zle_tricky.pro zle_utils.pro \
! zle_vi.pro zle_word.pro $(@D@YNAMIC_PROTO) \
! $(MODULE_DIR)/deltochar.pro $(MODULE_DIR)/example.pro
# object files
DYNAMIC_OBJS = module.o
***************
*** 151,162 ****
zle_vi.o zle_word.o $(@D@YNAMIC_OBJS)
# dynamically loadable modules
MODULES = $(MODULE_DIR)/deltochar.$(DL_EXT) $(MODULE_DIR)/example.$(DL_EXT)
MONULES =
LOBJS = main.o
NOBJS = $(LIBOBJS) main.o
! OBJS = $(LIBOBJS) $(LOBJS) $(MO@D@ULES)
LIBZSH = libzsh.so.$(VERSION)
NIBZSH =
--- 166,183 ----
zle_vi.o zle_word.o $(@D@YNAMIC_OBJS)
# dynamically loadable modules
+ MODOBJS = $(MODULE_DIR)/deltochar.o $(MODULE_DIR)/example.o
MODULES = $(MODULE_DIR)/deltochar.$(DL_EXT) $(MODULE_DIR)/example.$(DL_EXT)
MONULES =
LOBJS = main.o
NOBJS = $(LIBOBJS) main.o
! LSTMP =
! LLIST =
! NSTMP = stamp-modobjs
! NLIST = `cat stamp-modobjs`
!
! OBJS = $(LIBOBJS) $(LOBJS) $(MODOBJS) $(MO@D@ULES)
LIBZSH = libzsh.so.$(VERSION)
NIBZSH =
***************
*** 174,184 ****
modules: $(PROTO) $(ANSI@U@KNR) $(MO@D@ULES)
! zsh: $(PROTO) $(ANSI@U@KNR) $(@L@IBZSH) $(@L@OBJS)
! $(LINK) $(@L@OBJS) $(LIBS)
! $(LIBZSH): $(LIBOBJS)
! $(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $(LIBZSH) $(LIBOBJS)
ln -sf $(LIBZSH) libzsh.so
ansi2knr: ansi2knr.c
--- 195,205 ----
modules: $(PROTO) $(ANSI@U@KNR) $(MO@D@ULES)
! zsh: $(PROTO) $(ANSI@U@KNR) $(@L@IBZSH) $(@L@OBJS) $(@L@STMP)
! $(LINK) $(@L@OBJS) $(@L@LIST) $(LIBS)
! $(LIBZSH): $(LIBOBJS) $(NSTMP)
! $(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $(LIBZSH) $(LIBOBJS) $(NLIST)
ln -sf $(LIBZSH) libzsh.so
ansi2knr: ansi2knr.c
***************
*** 190,199 ****
$(OBJS): $(HDRS)
$(PROTO): makepro.sed
! $(MODULE_DIR)/deltochar.$(DL_EXT): $(MODULE_DIR)/deltochar.pro
! $(MODULE_DIR)/example.$(DL_EXT): $(MODULE_DIR)/example.pro
# ========== DEPENDENCIES FOR INSTALLING ==========
--- 211,241 ----
$(OBJS): $(HDRS)
+ init.o: bltinmods.list
+
+ bltinmods.list: $(MODBINS)
+ ( for mod in `cat $(MODBINS)`; do \
+ echo "DOMOD(mod_boot_$$mod, mod_cleanup_$$mod)"; \
+ done ) > $@
+
$(PROTO): makepro.sed
! $(NSTMP).force:
! dn=true; \
! test -f $(NSTMP) || dn=false; \
! echo > $(NSTMP).tmp; \
! for mod in `cat $(MODBINS)`; do \
! obj=$(MODULE_DIR)/$$mod.o; \
! echo $${obj}:; \
! $(MAKE) $(MAKEDEFS) $$obj; \
! echo $$obj >> $(NSTMP).tmp; \
! test $$obj -nt $(NSTMP) && dn=false; \
! done; \
! if $$dn && cmp -s $(NSTMP).tmp $(NSTMP); then \
! rm -f $(NSTMP).tmp; \
! else \
! mv -f $(NSTMP).tmp $(NSTMP); \
! fi
# ========== DEPENDENCIES FOR INSTALLING ==========
***************
*** 219,228 ****
DLCLEAN = $(MODULE_DIR)/*.$(DL_EXT) $(MODULE_DIR)/*.*.[co] $(MODULE_DIR)/*.pro
NLCLEAN =
mostlyclean:
! rm -f core *.o *~
clean: mostlyclean
! rm -f zsh ansi2knr $(@D@LCLEAN) signames.h *.*.c *.pro
distclean: clean
rm -f Makefile
--- 261,270 ----
DLCLEAN = $(MODULE_DIR)/*.$(DL_EXT) $(MODULE_DIR)/*.*.[co] $(MODULE_DIR)/*.pro
NLCLEAN =
mostlyclean:
! rm -f core stamp-modobjs* *.o $(MODULE_DIR)/*.o *~
clean: mostlyclean
! rm -f zsh ansi2knr $(@D@LCLEAN) signames.h bltinmods.list *.*.c *.pro
distclean: clean
rm -f Makefile
Index: Src/init.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/init.c,v
retrieving revision 1.23
diff -c -r1.23 init.c
*** init.c 1996/11/21 00:42:22 1.23
--- init.c 1996/11/22 01:43:46
***************
*** 820,822 ****
--- 820,835 ----
cc_first.refc = 10000;
cc_first.mask = 0;
}
+
+ #define DOMOD(boot, cleanup) int boot(Module);
+ #include "bltinmods.list"
+ #undef DOMOD
+
+ /**/
+ void
+ init_bltinmods(void)
+ {
+ #define DOMOD(boot, cleanup) boot(NULL);
+ #include "bltinmods.list"
+ #undef DOMOD
+ }
Index: Src/main.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/main.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 main.c
*** main.c 1996/11/21 00:03:58 1.1.1.1
--- main.c 1996/11/22 01:48:09
***************
*** 68,73 ****
--- 68,74 ----
setupvals();
init_signals();
global_heapalloc();
+ init_bltinmods();
run_init_scripts();
init_misc();
Index: Src/module.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/module.c,v
retrieving revision 1.10
diff -c -r1.10 module.c
*** module.c 1996/11/21 01:34:19 1.10
--- module.c 1996/11/22 01:49:45
***************
*** 48,53 ****
--- 48,61 ----
typedef int (*Module_func) _((Module));
+ #ifdef DLSYM_NEEDS_UNDERSCORE
+ # define MOD_BOOT "_mod_boot"
+ # define MOD_CLEANUP "_mod_cleanup"
+ #else /* !DLSYM_NEEDS_UNDERSCORE */
+ # define MOD_BOOT "mod_boot"
+ # define MOD_CLEANUP "mod_cleanup"
+ #endif /* !DLSYM_NEEDS_UNDERSCORE */
+
/**/
void *
load_module(char *name)
***************
*** 77,102 ****
int
init_module(Module m)
{
- char *s, *t;
- char buf[PATH_MAX + 1];
Module_func fn;
! s = strrchr(m->nam, '/');
! if (s) {
! s = dupstring(++s);
! t = strrchr(s, '.');
! if (t)
! *t = '\0';
! } else
! s = m->nam;
! if (strlen(s) + 6 > PATH_MAX)
! return 1;
! #ifdef DLSYM_NEEDS_UNDERSCORE
! sprintf(buf, "_boot_%s", s);
! #else
! sprintf(buf, "boot_%s", s);
! #endif
! fn = (Module_func)dlsym(m->handle, buf);
return fn ? fn(m) : 1;
}
--- 85,93 ----
int
init_module(Module m)
{
Module_func fn;
! fn = (Module_func)dlsym(m->handle, MOD_BOOT);
return fn ? fn(m) : 1;
}
***************
*** 104,129 ****
int
cleanup_module(Module m)
{
- char *s, *t;
- char buf[PATH_MAX + 1];
Module_func fn;
! s = strrchr(m->nam, '/');
! if (s) {
! s = dupstring(++s);
! t = strrchr(s, '.');
! if (t)
! *t = '\0';
! } else
! s = m->nam;
! if (strlen(s) + 9 > PATH_MAX)
! return 1;
! #ifdef DLSYM_NEEDS_UNDERSCORE
! sprintf(buf, "_cleanup_%s", s);
! #else
! sprintf(buf, "cleanup_%s", s);
! #endif
! fn = (Module_func)dlsym(m->handle, buf);
return fn ? fn(m) : 0;
}
--- 95,103 ----
int
cleanup_module(Module m)
{
Module_func fn;
! fn = (Module_func)dlsym(m->handle, MOD_CLEANUP);
return fn ? fn(m) : 0;
}
Index: Src/modules-bltin
===================================================================
*** /dev/null 1996/01/01 00:00:00
--- modules-bltin 1996/11/22 01:07:18
***************
*** 0 ****
--- 1 ----
+ example
Index: Src/Modules/deltochar.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/Modules/deltochar.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 deltochar.c
*** deltochar.c 1996/11/21 00:38:36 1.1.1.1
--- deltochar.c 1996/11/22 01:07:18
***************
*** 72,78 ****
/**/
int
! boot_deltochar(Module m)
{
int newfunc = addzlefunction("delete-to-char", deltochar, ZLE_DELETE);
if (newfunc > 0) {
--- 72,78 ----
/**/
int
! mod_boot(Module m)
{
int newfunc = addzlefunction("delete-to-char", deltochar, ZLE_DELETE);
if (newfunc > 0) {
***************
*** 86,92 ****
/**/
int
! cleanup_deltochar(Module m)
{
deletezlefunction(z_deltochar);
return 0;
--- 86,92 ----
/**/
int
! mod_cleanup(Module m)
{
deletezlefunction(z_deltochar);
return 0;
Index: Src/Modules/example.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/Modules/example.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 example.c
*** example.c 1996/11/21 00:38:36 1.1.1.1
--- example.c 1996/11/22 01:07:30
***************
*** 64,70 ****
/**/
int
! boot_example(Module m)
{
if (addbuiltin("example", 0, bin_example, 0, -1, "flags")) {
zwarnnam(m->nam, "name clash when adding builtin `example'", NULL, 0);
--- 64,70 ----
/**/
int
! mod_boot(Module m)
{
if (addbuiltin("example", 0, bin_example, 0, -1, "flags")) {
zwarnnam(m->nam, "name clash when adding builtin `example'", NULL, 0);
***************
*** 75,81 ****
/**/
int
! cleanup_example(Module m)
{
return deletebuiltin("example");
}
--- 75,81 ----
/**/
int
! mod_cleanup(Module m)
{
return deletebuiltin("example");
}
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBMpUMsHD/+HJTpU/hAQEg2AQAhY+lfnHgpQeG5BNGRvSDDdjtx1VkkSeA
rm8ZEOtcbIbqtgPfyfKSQYY3BybLphc3yAGTR+EiiSJycfJ3b8zvmnZiQVc2W55w
q6HnTDtbVm5pzuscIRKJDkejzLnpK2yPUkRBAN3OQjm2C5dSwXVVewMoONOxVSJt
9S6344p31Ww=
=UDi3
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author