Skip to content

Commit

Permalink
add abi compatibility detective.
Browse files Browse the repository at this point in the history
  • Loading branch information
monadbobo committed Jun 4, 2013
1 parent 96b7d2e commit f850bfb
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 5 deletions.
40 changes: 39 additions & 1 deletion auto/modules
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fi
if [ $HTTP_CACHE = YES ]; then
USE_MD5=YES
have=NGX_HTTP_CACHE . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_CACHE_TAG))
HTTP_SRCS="$HTTP_SRCS $HTTP_FILE_CACHE_SRCS"
fi

Expand Down Expand Up @@ -146,6 +147,7 @@ HTTP_FILTER_MODULES="$HTTP_WRITE_FILTER_MODULE \

if [ $HTTP_GZIP = YES ]; then
have=NGX_HTTP_GZIP . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_GZIP_TAG))
USE_ZLIB=YES
HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_GZIP_FILTER_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_GZIP_SRCS"
Expand All @@ -158,6 +160,7 @@ fi

if [ $HTTP_SSI = YES ]; then
have=NGX_HTTP_SSI . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_SSI_TAG))
HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_SSI_FILTER_MODULE"
HTTP_DEPS="$HTTP_DEPS $HTTP_SSI_DEPS"
HTTP_SRCS="$HTTP_SRCS $HTTP_SSI_SRCS"
Expand Down Expand Up @@ -241,12 +244,14 @@ HTTP_MODULES="$HTTP_MODULES $HTTP_STATIC_MODULE"

if [ $HTTP_GZIP_STATIC = YES ]; then
have=NGX_HTTP_GZIP . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_GZIP_STATIC_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_GZIP_STATIC_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_GZIP_STATIC_SRCS"
fi

if [ $HTTP_DAV = YES ]; then
have=NGX_HTTP_DAV . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_DAV_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_DAV_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_DAV_SRCS"
fi
Expand Down Expand Up @@ -325,6 +330,7 @@ fi
if [ $HTTP_REALIP = YES ]; then
have=NGX_HTTP_REALIP . auto/have
have=NGX_HTTP_X_FORWARDED_FOR . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_REALIP_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_REALIP_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_REALIP_SRCS"
fi
Expand All @@ -342,12 +348,14 @@ fi
if [ $HTTP_GEO = YES ]; then
have=NGX_HTTP_GEO . auto/have
have=NGX_HTTP_X_FORWARDED_FOR . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_GEO_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_GEO_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_GEO_SRCS"
fi

if [ $HTTP_GEOIP = YES ]; then
have=NGX_HTTP_X_FORWARDED_FOR . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_GEOIP_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_GEOIP_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_GEOIP_SRCS"
fi
Expand Down Expand Up @@ -402,6 +410,7 @@ fi
if [ $HTTP_SSL = YES ]; then
USE_OPENSSL=YES
have=NGX_HTTP_SSL . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_SSL_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_SSL_MODULE"
HTTP_DEPS="$HTTP_DEPS $HTTP_SSL_DEPS"
HTTP_SRCS="$HTTP_SRCS $HTTP_SSL_SRCS"
Expand All @@ -410,6 +419,7 @@ fi
if [ $HTTP_PROXY = YES ]; then
have=NGX_HTTP_PROXY . auto/have
have=NGX_HTTP_X_FORWARDED_FOR . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_PROXY_TAG))
#USE_MD5=YES
HTTP_MODULES="$HTTP_MODULES $HTTP_PROXY_MODULE"
HTTP_DEPS="$HTTP_DEPS $HTTP_PROXY_DEPS"
Expand Down Expand Up @@ -542,6 +552,7 @@ fi

if [ $HTTP_DEGRADATION = YES ]; then
have=NGX_HTTP_DEGRADATION . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_DEGRADATION_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_DEGRADATION_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_DEGRADATION_SRCS"
fi
Expand Down Expand Up @@ -608,6 +619,7 @@ fi

if [ $HTTP_UPSTREAM_CHECK = YES ]; then
have=NGX_HTTP_UPSTREAM_CHECK . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_UPSTREAM_CHECK_TAG))
HTTP_MODULES="$HTTP_MODULES $HTTP_UPSTREAM_CHECK_MODULE"
HTTP_SRCS="$HTTP_SRCS $HTTP_UPSTREAM_CHECK_SRCS"
fi
Expand Down Expand Up @@ -639,6 +651,7 @@ fi

if [ $HTTP_STUB_STATUS = YES ]; then
have=NGX_STAT_STUB . auto/have
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_STAT_STUB_TAG))
HTTP_MODULES="$HTTP_MODULES ngx_http_stub_status_module"
HTTP_SRCS="$HTTP_SRCS src/http/modules/ngx_http_stub_status_module.c"
fi
Expand Down Expand Up @@ -677,6 +690,8 @@ fi

if [ $NGX_SYSLOG = YES ]; then
CORE_MODULES="$CORE_MODULES ngx_syslog_module"

NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_SYSLOG_TAG))
fi

modules="$CORE_MODULES $EVENT_MODULES $PROCS_MODULES"
Expand All @@ -703,6 +718,14 @@ if [ $HTTP = YES ]; then
$HTTP_NOT_MODIFIED_FILTER_MODULE"

NGX_ADDON_DEPS="$NGX_ADDON_DEPS \$(HTTP_DEPS)"

NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_HTTP_TAG))
fi


if [ $NGX_DSO = YES ] ; then

have=NGX_DSO_ABI_COMPATIBILITY value="$NGX_DSO_ABI_COMPATIBILITY" . auto/define
fi


Expand Down Expand Up @@ -834,7 +857,22 @@ if [ $NGX_DSO = YES ] ; then

END

for mod in $NGX_ALL_MODULES

echo >> $NGX_MODULES_C
echo 'const char *ngx_dso_abi_all_tags[] = {' >> $NGX_MODULES_C

for tag in $NGX_DSO_ABI_ALL_TAG
do
echo " \"$tag\"," >> $NGX_MODULES_C
done

cat << END >> $NGX_MODULES_C
NULL
};

END

for mod in $NGX_ALL_MODULES
do
echo "module_stub $mod;" >> $NGX_MODULE_STUBS
done
Expand Down
50 changes: 50 additions & 0 deletions auto/options
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,45 @@ NGX_SHARED_PATH=
NGX_DSO_ALL_TARGETS=


NGX_DSO_ABI_ALL_TAG="
with-debug
with-http
with-http-cache
with-ipv6
with-syslog
with-http-gzip
with-http-gzip-satic
with-http-ssi
with-http-dav
with-http-realip
with-http-geoip
with-http-geo
with-http-ssl
with-http-proxy
with-http-degradation
with-http-upstream-check
with-http-stat-stub"

NGX_DSO_ABI_COMPATIBILITY=0x00000000
NGX_DSO_DEBUG_TAG=0x00000001
NGX_DSO_HTTP_TAG=0x00000002
NGX_DSO_CACHE_TAG=0x00000004
NGX_DSO_IPV6_TAG=0x00000008
NGX_DSO_SYSLOG_TAG=0x00000010
NGX_DSO_GZIP_TAG=0x00000020
NGX_DSO_GZIP_STATIC_TAG=0x00000040
NGX_DSO_SSI_TAG=0x00000080
NGX_DSO_DAV_TAG=0x00000100
NGX_DSO_REALIP_TAG=0x00000200
NGX_DSO_GEOIP_TAG=0x00000400
NGX_DSO_GEO_TAG=0x00000800
NGX_DSO_SSL_TAG=0x00001000
NGX_DSO_PROXY_TAG=0x00002000
NGX_DSO_DEGRADATION_TAG=0x00004000
NGX_DSO_UPSTREAM_CHECK_TAG=0x00008000
NGX_DSO_STAT_STUB_TAG=0x00010000


HTTP=YES

NGX_HTTP_LOG_PATH=
Expand Down Expand Up @@ -1057,6 +1096,17 @@ if [ $HTTP = NO ]; then
HTTP_PROXY=NO
HTTP_FASTCGI=NO
HTTP_FASTCGI_SHARED=NO

fi


if [ $NGX_DEBUG = YES ]; then
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_DEBUG_TAG))
fi


if [ $NGX_IPV6 = YES ]; then
NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_IPV6_TAG))
fi


Expand Down
7 changes: 4 additions & 3 deletions src/core/ngx_conf_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ struct ngx_open_file_s {
};


#define NGX_NUMBER_MAJOR 2
#define NGX_NUMBER_MAJOR 3
#define NGX_NUMBER_MINOR 1

#define NGX_MODULE_V1 0, 0, 0, 0, 0, NGX_NUMBER_MAJOR, NGX_NUMBER_MINOR
#define NGX_MODULE_V1 0, 0, 0, 0, \
NGX_DSO_ABI_COMPATIBILITY, NGX_NUMBER_MAJOR, NGX_NUMBER_MINOR
#define NGX_MODULE_V1_PADDING 0, 0, 0, 0, 0, 0, 0, 0

struct ngx_module_s {
Expand All @@ -107,7 +108,7 @@ struct ngx_module_s {

ngx_uint_t spare0;
ngx_uint_t spare1;
ngx_uint_t spare2;
ngx_uint_t abi_compatibility;

ngx_uint_t major_version;
ngx_uint_t minor_version;
Expand Down
38 changes: 37 additions & 1 deletion src/core/ngx_dso_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ static ngx_dso_flagpole_t module_flagpole[] = {
{ ngx_null_string, ngx_null_string}
};

extern const char *ngx_dso_abi_all_tags[];


static void *
ngx_dso_create_conf(ngx_cycle_t *cycle)
Expand Down Expand Up @@ -499,6 +501,26 @@ ngx_dso_save(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}


static void
ngx_dso_show_abi_compatibility(ngx_uint_t abi_compatibility)
{
ngx_uint_t i;

for (i = 0; i < sizeof(ngx_uint_t) * 8; i++) {

if (ngx_dso_abi_all_tags[i] == NULL) {
break;
}

if (abi_compatibility & 0x1) {
ngx_log_stderr(0, " %s", ngx_dso_abi_all_tags[i]);
}

abi_compatibility >>= 1;
}
}


static char *
ngx_dso_load(ngx_conf_t *cf)
{
Expand Down Expand Up @@ -531,14 +553,28 @@ ngx_dso_load(ngx_conf_t *cf)
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"module \"%V\" is not compatible with this "
"version of nginx "
"version of tengine "
"(require %ui.%ui, found %ui.%ui).",
&dm[i].name, NGX_NUMBER_MAJOR, NGX_NUMBER_MINOR,
dm[i].module->major_version,
dm[i].module->minor_version);
return NGX_CONF_ERROR;
}

if (dm[i].module->abi_compatibility != NGX_DSO_ABI_COMPATIBILITY)
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"module \"%V\" is not compatible with this "
"ABI of tengine, you need recomplie module",
&dm[i].name);

ngx_log_stderr(0, "Tengine config option: ");
ngx_dso_show_abi_compatibility(NGX_DSO_ABI_COMPATIBILITY);
ngx_log_stderr(0, "module \"%V\" config option: ", &dm[i].name);
ngx_dso_show_abi_compatibility(dm[i].module->abi_compatibility);
return NGX_CONF_ERROR;
}

postion = ngx_dso_find_postion(ctx, dm[i].name);

ngx_log_debug2(NGX_LOG_DEBUG_CORE, cf->log, 0,
Expand Down

0 comments on commit f850bfb

Please sign in to comment.