httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Sutton <p...@awe.com>
Subject Shared modules on Unix
Date Sun, 07 Dec 1997 15:05:21 GMT
I've been playing with mod_so on Unix, and it looks pretty good. It would
very nice to allow third party modules to be loaded at run time, or even
normal Apache modules. We could distribute, for example, a binary
containing just the default modules, with extra modules available as
shared libraries (e.g. mod_rewrite, mod_proxy) for loading only _if_ the
end use wants them. 

Anyway to make compiling modules for shared libraries easier, the patch
below updates Configure. Now as well as AddModule you can also use
SharedModule, like this:

  SharedModule modules/standard/mod_rewrite.so

(you have to change the extension from .o to .so). When ./Configure runs
it will create module makefiles that build the SharedModule modules to .so
files. To do this Configure has to know about the compiler and linker
options required: I've put some default ones in for FreeBSD and Linux. 
This can also be set in the Configuration file (if set here, it will
override the defaults contained within the Configure script). Oh, and if
there are no SharedModule lines none of these extra options will be used
anywhere in the build process.

The Configure variables and Configuration options are

  CFLAGS_SHLIB     Options when building .o files ready for sharing
                   (e.g. -fpic)
  LDFLAGS_SHLIB    Options when linking .o files to .so (e.g. -Bshareable,
                   -export, -assert pure-text)
  LDFLAGS_SHLIB_EXPORT
                   Options required when linking httpd so that it exports
                   its symbols for linking at runtime (e.g. -Bdynamic,
                   -rdynamic, -export-dynamic)

The options used in Configure could be placed in Configuration like this:

  CFLAGS_SHLIB=-fpic
  LDFLAGS_SHLIB=-Bshareable
  LDFLAGS_SHLIB_EXPORT=-rdynamic

Other systems may need to alter these. 

I've tried this out by converting _all_ the AddModules to SharedModule
lines, and adding AddModule modules/extra/mod_so.o and it seems to work.
You can get a minimal httpd (just http_core.o and mod_so.o) and
dynamically load every other module. I've only been testing on Linux. 

//pcs

Index: Configure
===================================================================
RCS file: /export/home/cvs/apachen/src/Configure,v
retrieving revision 1.173
diff -u -r1.173 Configure
--- Configure	1997/11/30 19:17:22	1.173
+++ Configure	1997/12/07 14:15:57
@@ -69,9 +69,12 @@
  sed 's/^Rule[ 	]*/##Rule:/' | \
  sed 's/^[ 	]*AddModule/AddModule/' | \
  sed 's/^[        ]*%AddModule/%AddModule/' | \
+ sed 's/^[        ]*SharedModule/SharedModule/' | \
  sed 's/^[ 	]*Module/Module/' | \
  sed 's/^[        ]*%Module/%Module/' > $tmpfile
 
+using_shlib=`grep -q ^SharedModule $tmpfile && echo 1`
+
 #
 # Only "assignment" ("=") statements and Module lines
 # should be left at this point. If there is other stuff
@@ -79,6 +82,7 @@
 #
 if egrep -v '^%?Module[ 	]+[A-Za-z0-9_]+[ 	]+[^ 	]+$' $tmpfile \
  | egrep -v '^%?AddModule[ 	]+[^ 	]+$' \
+ | egrep -v '^SharedModule[ 	]+[^ 	]+$' \
  | grep -v = > /dev/null
 then
   echo "Syntax error --- The configuration file is used only to"
@@ -86,6 +90,7 @@
   echo "options or Configure rules, and I don't see that at all:"
   egrep -v '^%?Module[ 	]+[A-Za-z0-9_]+[ 	]+[^ 	]+$' $tmpfile \
    | egrep -v '^%?AddModule[ 	]+[^ 	]+$'  \
+   | egrep -v '^%?SharedModule[ 	]+[^ 	]+$'  \
    | grep -v =
   exitcode=1
   exit 1
@@ -312,11 +317,15 @@
 	OS='Linux'
 	CFLAGS="$CFLAGS -DLINUX=2"
 	LIBS="$LIBS -lm"
+	CFLAGS_SHLIB="-fpic"
+	LDFLAGS_SHLIB="-Bshareable"
 	;;
     *-linux1)
 	DEF_WANTHSREGEX=yes
 	OS='Linux'
 	CFLAGS="$CFLAGS -DLINUX=1"
+	CFLAGS_SHLIB="-fpic"
+	LDFLAGS_SHLIB="-Bshareable"
 	;;
     *-lynx-lynxos)
 	OS='LynxOS 2.x'
@@ -348,6 +357,8 @@
 	LIBS="$LIBS -lcrypt"
 	DBM_LIB=""
 	DB_LIB=""
+	CFLAGS_SHLIB="-fpic"
+	LDFLAGS_SHLIB="-Bshareable"
 	;;
     *-openbsd*)
 	OS='OpenBSD'
@@ -624,6 +635,8 @@
 # Look for OPTIM and save for later
 #
 TOPTIM=`egrep '^OPTIM=' Makefile.config | tail -1 | awk -F= '{print $2}'`
+TLDFLAGS_SHLIB=`egrep '^LDFLAGS_SHLIB=' Makefile.config | tail -1 | awk -F= '{print $2}'`
+TCFLAGS_SHLIB=`egrep '^CFLAGS_SHLIB=' Makefile.config | tail -1 | awk -F= '{print $2}'`
 
 ####################################################################
 # Set the value of CC if need be
@@ -632,6 +645,26 @@
     echo "CC=$CC" >> Makefile.config
 fi
 
+if [ "x$using_shlib" = "x1" ] ; then
+    #
+    # Set the value of the shared libary flags, if they aren't explicitly
+    # set in the configuration file
+    #
+    if [ "x$TCFLAGS_SHLIB" = "x" ]; then
+        echo "CFLAGS_SHLIB=$CFLAGS_SHLIB" >> Makefile.config
+    fi
+    if [ "x$TLDFLAGS_SHLIB" = "x" ]; then
+        echo "LDFLAGS_SHLIB=$LDFLAGS_SHLIB" >> Makefile.config
+    fi
+    if [ "x$TLDFLAGS_SHLIB_EXPORT" = "x" ]; then
+        if [ "x$TCC" = "xgcc" ] ||
+    	[ "x$TCC" = "x" -a "x$CC" = "xgcc" ] ; then
+    	LDFLAGS_SHLIB_EXPORT=-rdynamic
+        fi
+        echo "LDFLAGS_SHLIB_EXPORT=$LDFLAGS_SHLIB_EXPORT" >> Makefile.config
+    fi
+fi	# end of $using_shlib section
+
 ####################################################################
 # Now we do some OS specific adjustments... for some OSs, we need
 # to adjust CFLAGS and/or OPTIM depending on which compiler we
@@ -782,7 +815,7 @@
 		SEEN[pp[2]] = 1
 	    }
     	}
-	($1 == "AddModule" && $2 ~ /^modules\//) { 
+	(($1 == "AddModule" || $1 == "SharedModule") && $2 ~ /^modules\//) { 
 	    split ($2, pp, "/")
 	    if (! SEEN[pp[2]]) {
 		printf "%s ", pp[2]
@@ -1078,10 +1111,35 @@
 		    printf "\n"
 		}'
 
+	    cat << 'EOF' >> $moddir/Makefile
+
+all: lib shlib
+
+EOF
 	    echo "LIB=lib$basedir.a" >> $moddir/Makefile
+	    awk >> $moddir/Makefile < $tmpfile '
+	    ($1 == "SharedModule" && $2 ~ /^modules\/'$basedir'\//) {
+		split($2, pp, "/")
+		shlibs=shlibs " " pp[3]
+		so=pp[3]
+		split(pp[3], parts, ".")
+		base=parts[1]
+		shlibsobj=shlibsobj " " base "-so.o"
+		comp=comp base ".so: " base "-so.o\n"
+		comp=comp "	$(LD) $(LDFLAGS) $(LDFLAGS_SHLIB) -o " base ".so $<\n"
+		comp=comp base "-so.o: " base ".c\n"
+		comp=comp "	$(CC) $(CFLAGS) $(INCLUDES) $(CFLAGS_SHLIB) -c -o " base "-so.o $<\n"
+	    }
+	    END { 
+		printf "SHLIBS=%s\n", shlibs;
+		printf "SHLIBS_OBJ=%s\n", shlibsobj;
+		print "\n" comp "\n" }'
+
 	    cat << 'EOF' >> $moddir/Makefile
 
-all:	$(LIB)
+lib:	$(LIB) 
+
+shlib:	$(SHLIBS)
 
 $(LIB): $(OBJS)
 	rm -f $@
@@ -1092,9 +1150,9 @@
 	$(CC) -c $(INCLUDES) $(CFLAGS) $(SPACER) $<
 
 clean:
-	rm -f *.o $(LIB)
+	rm -f *.o $(LIB) $(SHLIB)
 
-$(OBJS): Makefile
+$(OBJS) $(SHLIBS) $(SHLIBS_OBJ): Makefile
 EOF
 	fi
 
Index: Makefile.tmpl
===================================================================
RCS file: /export/home/cvs/apachen/src/Makefile.tmpl,v
retrieving revision 1.73
diff -u -r1.73 Makefile.tmpl
--- Makefile.tmpl	1997/11/30 19:17:23	1.73
+++ Makefile.tmpl	1997/12/07 14:15:57
@@ -29,7 +29,7 @@
 
 $(TARGET):  subdirs modules.o
 	$(CC) -c $(CFLAGS) buildmark.c
-	$(CC) $(CFLAGS) $(LDFLAGS)  -o $(TARGET) buildmark.o $(OBJS) $(REGLIB) $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SHLIB_EXPORT) -o $(TARGET) buildmark.o $(OBJS) $(REGLIB)
$(LIBS)
 
 subdirs:
 	for i in $(SUBDIRS); do \



Mime
View raw message