You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by "Ralf S. Engelschall" <rs...@apache.org> on 1998/08/03 10:44:11 UTC
cvs commit: apache-1.3/htdocs/manual dso.html
rse 98/08/03 01:44:10
Modified: src CHANGES Configuration.tmpl Configure
src/modules/proxy Makefile.tmpl
src/support Makefile.tmpl apxs.pl
htdocs/manual dso.html
Added: src/helpers slo.sh
Log:
Link DSO modules against possible libraries from $(LIBS) (take 2)
=================================================================
Currently we have the following entry in our dso.html document:
| Because DSO modules cannot be linked against other DSO-based libraries (ld
| -lfoo) on all platforms (for instance a.out-based platforms usually don't
| provide this functionality while ELF-based platforms do) you cannot use the
| DSO mechanism for all types of modules. Or in other words, modules compiled as
| DSO files are restricted to only use symbols from the Apache core, from the C
| library (libc) and all other dynamic or static libraries used by the Apache
| core, or from static library archives (libfoo.a) containing position
| independend code. The only chance to use other code is to either make sure the
| Apache core itself already contains a reference to it or loading the code
| yourself via dlopen().
The important part here is: "cannot be linked .... on all platforms". But
there _are_ platform (especially ELF-based ones) which support linking DSO
files agains other DSO files. And even on platforms where this is not
possible is it possible to at least link against libraries assuming they
contain PIC code.
So, the idea is this: In the configuration process we already determine the
variable LDFLAGS and LIBS. They hold -L and -l options for linking
executables. We parse these options and separate them into three classes:
OBJ, PIC and DSO. And then we re-assemble a LIBS_SHLIB variable from only the
options in classes PIC and DSO. This variable is then used on the build
command for mod_xxx.so.
Example:
| $ ./configure --prefix=/tmp/apache \
| --enable-module=auth_db \
| --enable-shared=auth_db \
| --enable-rule=SHARED_CHAIN
Without SHARED_CORE the mod_auth_db.so cannot be linked or at least not loaded
correctly under run-time. With SHARED_CHAIN enabled it is linked against the
libdb.so and all is fine (at least under this ELF-based Debian box I tried):
| :> make mod_auth_db.so
| gcc -c -I../../os/unix -I../../include -I/usr/include/ -DLINUX=2
| -DUSE_HSREGEX `../../apaci` -fpic -DSHARED_MODULE mod_auth_db.c && mv
| mod_auth_db.o mod_auth_db.lo
| ld -Bshareable -o mod_auth_db.so mod_auth_db.lo -lm -ldb
| root@gw1:/e/apache/SRC/WORK/apache-1.3-libsshlib/src/modules/standard
| :> ldd mod_auth_db.so
| ./mod_auth_db.so => ./mod_auth_db.so
| libc.so.5 => /lib/libc.so.5
| libm.so.5 => /lib/libm.so.5
| libdb.so.1 => /usr/lib/libdb.so.1
This way we provide the maximum we can provide. Sure, on some platforms the
user still has no chance. But this shouldn't mean he becomes no chance on
other platforms where there _is_ a chance. So this patch is a first step for
more friendly and flexible DSO support.
The complete mechanism is triggered by a new Rule named SHARED_CHAIN. To avoid
problems this is DISABLED(!) for ALL(!) platforms currently. But when
experience shows that it worked fine for users we can enable it for tested
platforms per default.
Revision Changes Path
1.997 +9 -0 apache-1.3/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v
retrieving revision 1.996
retrieving revision 1.997
diff -u -r1.996 -r1.997
--- CHANGES 1998/08/03 07:34:01 1.996
+++ CHANGES 1998/08/03 08:44:03 1.997
@@ -1,5 +1,14 @@
Changes with Apache 1.3.2
+ *) Add new Rule SHARED_CHAIN which can be used to enable linking of DSO
+ files (here modules) against other DSO files (here shared libraries).
+ This is done by determining a subset of LIBS which can be safely used for
+ linking the DSOs, i.e. PIC libs and shared libs. Currently the rule is
+ disabled for all platforms to avoid problems with this (experimental)
+ rule. But we provide it now for those people how ran into problems and
+ want to came out by forcing linking against DSOs.
+ [Ralf S. Engelschall] PR#2587
+
*) Fix suEXEC start message: Has to be of `notice' level to really get
printed together with the standard startup message because the `notice'
level is handled special inside ap_log_error() for startup messages.
1.108 +14 -0 apache-1.3/src/Configuration.tmpl
Index: Configuration.tmpl
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/Configuration.tmpl,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- Configuration.tmpl 1998/07/23 13:57:51 1.107
+++ Configuration.tmpl 1998/08/03 08:44:03 1.108
@@ -89,6 +89,19 @@
# Then enable the DSO feature for particular modules individually
# by replacing their `AddModule' command with `SharedModule' and
# change the filename extension from `.o' to `.so'.
+#
+# Sometimes the DSO files need to be linked against other shared
+# libraries to explicitly resolve symbols from them when the
+# httpd program not already contains references to them. For
+# instance when buidling mod_auth_db as a DSO you need to link
+# the DSO against the libdb explicity because the Apache kernel
+# has no references for this library. But the problem is that
+# this "chaining" is not supported on all platforms. Although one
+# usually can link a DSO against another DSO without linker
+# complains the linkage is not really done on these platforms.
+# So, when you receive "unresolved symbol" errors under runtime
+# when using the LoadModule directive for a particular module try
+# to enable the SHARED_CHAIN rule below.
#CFLAGS_SHLIB=
#LD_SHLIB=
@@ -96,6 +109,7 @@
#LDFLAGS_SHLIB_EXPORT=
Rule SHARED_CORE=default
+Rule SHARED_CHAIN=default
################################################################
# Rules configuration
1.281 +24 -1 apache-1.3/src/Configure
Index: Configure
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/Configure,v
retrieving revision 1.280
retrieving revision 1.281
diff -u -r1.280 -r1.281
--- Configure 1998/07/21 10:20:25 1.280
+++ Configure 1998/08/03 08:44:04 1.281
@@ -77,6 +77,7 @@
# (i.e., a simple "sanity check")
# mfhead:
# fp2rp:
+# slo.sh:
exitcode=0
trap 'rm -f $tmpfile $tmpfile2 $tmpfile3 $tmpconfig $awkfile; exit $exitcode' 0 1 2 3 15
@@ -237,6 +238,7 @@
RULE_IRIXN32=`./helpers/CutRule IRIXN32 $file`
RULE_PARANOID=`./helpers/CutRule PARANOID $file`
RULE_SHARED_CORE=`./helpers/CutRule SHARED_CORE $file`
+RULE_SHARED_CHAIN=`./helpers/CutRule SHARED_CHAIN $file`
####################################################################
## Rule SHARED_CORE implies required DSO support
@@ -812,6 +814,7 @@
if [ "x$using_shlib" = "x1" ] ; then
LD_SHLIB="ld"
DEF_SHARED_CORE=no
+ DEF_SHARED_CHAIN=no
SHLIB_SUFFIX_DEPTH=all
SHLIB_EXPORT_FILES=no
case "$PLAT" in
@@ -1375,6 +1378,25 @@
fi
####################################################################
+## Now the SHARED_CHAIN stuff
+##
+LIBS_SHLIB=''
+if [ "x$using_shlib" = "x1" ] ; then
+ if [ ".$RULE_SHARED_CHAIN" = .default ] ; then
+ RULE_SHARED_CHAIN=$DEF_SHARED_CHAIN
+ fi
+ if [ ".$RULE_SHARED_CHAIN" = .yes ]; then
+ echo " + enabling DSO files to be linked against others"
+ # determine libraries which can be safely linked
+ # to our DSO files, i.e. PIC libraries and shared libraries
+ extra_ldflags="`grep EXTRA_LDFLAGS= Makefile.config`"
+ extra_libs="`grep EXTRA_LIBS= Makefile.config`"
+ eval "`./helpers/slo.sh $LDFLAGS $LIBS $extra_ldflags $extra_libs`"
+ LIBS_SHLIB="$SLO_DIRS_PIC $SLO_LIBS_PIC $SLO_DIRS_DSO $SLO_LIBS_DSO"
+ fi
+fi
+
+####################################################################
## Now the SHARED_CORE stuff
##
if [ "x$using_shlib" = "x1" ] ; then
@@ -1600,6 +1622,7 @@
echo "INCDIR=\$(SRCDIR)/include" >>Makefile.config
echo "INCLUDES0=-I\$(OSDIR) -I\$(INCDIR)">> Makefile.config
echo "INCLUDES1=$INCLUDES">> Makefile.config
+echo "LIBS_SHLIB=$LIBS_SHLIB">> Makefile.config
echo "LDFLAGS1=$LDFLAGS">> Makefile.config
echo "MFLAGS_STATIC=$MFLAGS_STATIC">> Makefile.config
echo "REGLIB=$REGLIB">> Makefile.config
@@ -1839,7 +1862,7 @@
.c.so:
$(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $< && mv $*.o $*.lo
- $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $*.lo
+ $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $*.lo $(LIBS_SHLIB)
clean:
rm -f $(LIB) $(OBJS) $(SHLIBS) $(OBJS_PIC)
1.1 apache-1.3/src/helpers/slo.sh
Index: slo.sh
===================================================================
#!/bin/sh
##
## slo.h -- (S)eparate (L)inker (O)ptions by library class
## Written by Ralf S. Engelschall <rs...@apache.org>
##
DIFS='
'
#
# parse out -L and -l options from command line
#
DIRS=''
LIBS=''
ARGV=''
optprev=""
OIFS="$IFS" IFS="$DIFS"
for opt
do
# concatenate with previous option if exists
if [ ".$optprev" != . ]; then
opt="${optprev}${opt}";
optprev=''
fi
# remember options for arg when used stand-alone
if [ ".$opt" = ".-L" -o ".$opt" = ".-l" ]; then
optprev="$opt"
continue;
fi
# split argument into option plus option argument
arg="`echo $opt | cut -c3-`"
opt="`echo $opt | cut -c1-2`"
# store into containers
case $opt in
-L) DIRS="$DIRS:$arg" ;;
-l) LIBS="$LIBS:$arg" ;;
*) ARGV="$ARGV $opt" ;;
esac
done
IFS="$OIFS"
#
# set linker default directories
#
DIRS_DEFAULT='/lib:/usr/lib'
if [ ".$LD_LIBRARY_PATH" != . ]; then
DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
fi
#
# sort options by class
#
DIRS_OBJ=''
LIBS_OBJ=''
DIRS_PIC=''
LIBS_PIC=''
DIRS_DSO=''
LIBS_DSO=''
# for each library...
OIFS="$IFS" IFS=':'
for lib in $LIBS; do
[ ".$lib" = . ] && continue
found='no'
found_indefdir='no'
found_type=''
found_dir=''
# for each directory...
OIFS2="$IFS" IFS=":$DIFS"
for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
[ ".$dir" = . ] && continue
[ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
[ ! -d $dir ] && continue
# search the file
OIFS3="$IFS" IFS="$DIFS"
for file in '' `cd $dir && ls lib${lib}.* 2>/dev/null`; do
[ ".$file" = . ] && continue
case $file in
*.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
found=yes;
found_type=DSO;
break
;;
*.lo|*.la )
found=yes;
found_type=PIC
;;
*.a )
if [ ".$found_type" = . ]; then
found=yes
found_type=OBJ
fi
;;
esac
done
IFS="$OIFS3"
if [ ".$found" = .yes ]; then
found_dir="$dir"
break
fi
done
IFS="$OIFS2"
if [ ".$found" = .yes ]; then
if [ ".$found_indefdir" != .yes ]; then
eval "dirlist=\"\${DIRS_${found_type}}:\""
if [ ".`echo \"$dirlist\" | fgrep :$found_dir:`" = . ]; then
eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\""
fi
eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
else
eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
fi
else
LIBS_OBJ="$LIBS_OBJ:$lib"
#dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
#echo "splitlibs:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
#echo "splitlibs:Warning: $dirlist" 1>&1
fi
done
IFS="$OIFS"
#
# also pass-through unused dirs even if it's useless
#
OIFS="$IFS" IFS=':'
for dir in $DIRS; do
dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
if [ ".`echo \"$dirlist\" | fgrep :$dir:`" = . ]; then
DIRS_OBJ="$DIRS_OBJ:$dir"
fi
done
IFS="$OIFS"
#
# reassemble the options but seperated by type
#
OIFS="$IFS" IFS="$DIFS"
for type in OBJ PIC DSO; do
OIFS2="$IFS" IFS=':'
eval "libs=\"\$LIBS_${type}\""
opts=''
for lib in $libs; do
[ ".$lib" = . ] && continue
opts="$opts -l$lib"
done
eval "LIBS_${type}=\"$opts\""
eval "dirs=\"\$DIRS_${type}\""
opts=''
for dir in $dirs; do
[ ".$dir" = . ] && continue
opts="$opts -L$dir"
done
eval "DIRS_${type}=\"$opts\""
IFS="$OIFS2"
done
IFS="$OIFS"
#
# give back results
#
OIFS="$IFS" IFS="$DIFS"
for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
eval "val=\"\$${var}\""
val="`echo $val | sed -e 's/^ *//'`"
echo "SLO_${var}=\"${val}\""
done
IFS="$OIFS"
##EOF##
1.23 +1 -1 apache-1.3/src/modules/proxy/Makefile.tmpl
Index: Makefile.tmpl
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/proxy/Makefile.tmpl,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Makefile.tmpl 1998/07/13 11:32:45 1.22
+++ Makefile.tmpl 1998/08/03 08:44:07 1.23
@@ -19,7 +19,7 @@
libproxy.so: $(OBJS_PIC)
rm -f $@
- $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(OBJS_PIC)
+ $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(OBJS_PIC) $(LIBS_SHLIB)
.SUFFIXES: .o .lo
1.25 +3 -2 apache-1.3/src/support/Makefile.tmpl
Index: Makefile.tmpl
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/support/Makefile.tmpl,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Makefile.tmpl 1998/07/13 11:32:57 1.24
+++ Makefile.tmpl 1998/08/03 08:44:08 1.25
@@ -31,10 +31,11 @@
apxs: apxs.pl
sed <apxs.pl >apxs \
-e 's%@CC@%$(CC)%g' \
- -e 's%@LD_SHLIB@%$(LD_SHLIB)%g' \
-e 's%@CFLAGS@%$(CFLAGS)%g' \
-e 's%@CFLAGS_SHLIB@%$(CFLAGS_SHLIB)%g' \
- -e 's%@LDFLAGS_SHLIB@%$(LDFLAGS_SHLIB)%g' && chmod a+x apxs
+ -e 's%@LD_SHLIB@%$(LD_SHLIB)%g' \
+ -e 's%@LDFLAGS_SHLIB@%$(LDFLAGS_SHLIB)%g' \
+ -e 's%@LIBS_SHLIB@%$(LIBS_SHLIB)%g' && chmod a+x apxs
suexec: suexec.o
$(CC) $(CFLAGS) suexec.o -o suexec $(LDFLAGS) $(LIBS)
1.10 +2 -0 apache-1.3/src/support/apxs.pl
Index: apxs.pl
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/support/apxs.pl,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- apxs.pl 1998/05/28 10:55:18 1.9
+++ apxs.pl 1998/08/03 08:44:08 1.10
@@ -73,6 +73,7 @@
my $CFG_CFLAGS_SHLIB = '@CFLAGS_SHLIB@'; # substituted via Makefile.tmpl
my $CFG_LD_SHLIB = '@LD_SHLIB@'; # substituted via Makefile.tmpl
my $CFG_LDFLAGS_SHLIB = '@LDFLAGS_SHLIB@'; # substituted via Makefile.tmpl
+my $CFG_LIBS_SHLIB = '@LIBS_SHLIB@'; # substituted via Makefile.tmpl
my $CFG_PREFIX = '@prefix@'; # substituted via APACI install
my $CFG_SBINDIR = '@sbindir@'; # substituted via APACI install
my $CFG_INCLUDEDIR = '@includedir@'; # substituted via APACI install
@@ -352,6 +353,7 @@
$opt .= " -l$opt_l";
}
$cmd .= $opt;
+ $cmd .= " $CFG_LIBS_SHLIB";
push(@cmds, $cmd);
# execute the commands
1.7 +5 -3 apache-1.3/htdocs/manual/dso.html
Index: dso.html
===================================================================
RCS file: /export/home/cvs/apache-1.3/htdocs/manual/dso.html,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- dso.html 1998/07/06 11:54:30 1.6
+++ dso.html 1998/08/03 08:44:10 1.7
@@ -364,9 +364,11 @@
use symbols from the Apache core, from the C library (<CODE>libc</CODE>)
and all other dynamic or static libraries used by the Apache core, or
from static library archives (<CODE>libfoo.a</CODE>) containing position
- independent code. The only chance to use other code is to either make
- sure the Apache core itself already contains a reference to it or loading
- the code yourself via <CODE>dlopen()</CODE>.
+ independent code. The only chances to use other code is to either make
+ sure the Apache core itself already contains a reference to it, loading
+ the code yourself via <CODE>dlopen()</CODE> or enabling the
+ <CODE>SHARED_CHAIN</CODE> rule while building Apache when your platform
+ supports linking DSO files against DSO libraries.
<P>
<LI> Under some platforms (many SVR4 systems) there is no way to force the
linker to export all global symbols for use in DSO's when linking the