Improve the build system to *properly* remove unnecessary symbols from the runtime global namespace. Along the way, change the prefixes on some internal-only API calls to use a common prefix.

With these changes, for a module to export symbols into the global namespace, it must have *both* the AST_MODFLAG_GLOBAL_SYMBOLS flag and a linker script that allows the linker to leave the symbols exposed in the module's .so file (see res_odbc.exports for an example).



git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@182808 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2009-03-18 01:55:22 +00:00
parent 59f867a5cb
commit 7e1ee720ba
22 changed files with 191 additions and 59 deletions

View File

@@ -51,8 +51,13 @@ endif
# per-target settings will be applied
CC_CFLAGS=$(PTHREAD_CFLAGS) $(ASTCFLAGS)
CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(ASTCFLAGS))
CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK)
CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK)
ifeq ($(GNU_LD),1)
SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(if $(wildcard $(subst .so,.exports,$@)),$(subst .so,.exports,$@),$(ASTTOPDIR)/default.exports)
endif
CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS)
CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS)
CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)

View File

@@ -1,37 +0,0 @@
#!/bin/sh -e
# This script is designed to remove all non-API global symbols from an object
# file. The only global symbols that should be retained are those that belong
# to the official namespace. Unfortunately doing this is platform-specific, as
# the object file manipulation tools are not consistent across platforms.
#
# On platforms where this script does not know what to do, the object file
# will retain non-API global symbols, and this may have unpleasant side effects.
#
# Prefixes that belong to the official namespace are:
# ast_
# _ast_
# __ast_
# astman_
# pbx_
case "${PROC}" in
powerpc64)
TEXTSYM=" D "
;;
*)
TEXTSYM=" T "
;;
esac
FILTER="${GREP} -v -e ^ast_ -e ^_ast_ -e ^__ast_ -e ^astman_ -e ^pbx_"
case "${OSARCH}" in
linux-gnu)
nm ${1} | ${GREP} -e "$TEXTSYM" | cut -d" " -f3 | ${FILTER} > striplist
sed -e "s/^/-N /" striplist | xargs -n 40 ${STRIP} ${1}
rm -f striplist
;;
*)
;;
esac

4
default.exports Normal file
View File

@@ -0,0 +1,4 @@
{
local:
*;
};

View File

@@ -188,15 +188,15 @@ int ao2_ref(void *o, int delta);
#ifndef DEBUG_THREADS
int ao2_lock(void *a);
#else
#define ao2_lock(a) _ao2_lock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int _ao2_lock(void *a, const char *file, const char *func, int line, const char *var);
#define ao2_lock(a) __ao2_lock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int __ao2_lock(void *a, const char *file, const char *func, int line, const char *var);
#endif
#ifndef DEBUG_THREADS
int ao2_trylock(void *a);
#else
#define ao2_trylock(a) _ao2_trylock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int _ao2_trylock(void *a, const char *file, const char *func, int line, const char *var);
#define ao2_trylock(a) __ao2_trylock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int __ao2_trylock(void *a, const char *file, const char *func, int line, const char *var);
#endif
/*!
@@ -208,8 +208,8 @@ int _ao2_trylock(void *a, const char *file, const char *func, int line, const ch
#ifndef DEBUG_THREADS
int ao2_unlock(void *a);
#else
#define ao2_unlock(a) _ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int _ao2_unlock(void *a, const char *file, const char *func, int line, const char *var);
#define ao2_unlock(a) __ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int __ao2_unlock(void *a, const char *file, const char *func, int line, const char *var);
#endif
/*!

View File

@@ -94,6 +94,10 @@ ifeq ($(OSARCH),SunOS)
ASTLINK=
endif
ifeq ($(GNU_LD),1)
ASTLINK+=-Wl,--version-script,asterisk.exports
endif
editline/libedit.a:
cd editline && test -f config.h || CFLAGS="$(PTHREAD_CFLAGS) $(subst $(ASTTOPDIR),../../,$(ASTCFLAGS:-Werror=))" LDFLAGS="$(ASTLDFLAGS)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM) --with-ncurses=$(NCURSES_DIR) --with-curses=$(CURSES_DIR) --with-termcap=$(TERMCAP_DIR) --with-tinfo=$(TINFO_DIR)
$(MAKE) -C editline libedit.a
@@ -133,20 +137,19 @@ else
H323LDLIBS=
endif
asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS)
asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) asterisk.exports
@$(ASTTOPDIR)/build_tools/make_build_h > $(ASTTOPDIR)/include/asterisk/build.h.tmp
@if cmp -s $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; then echo ; else \
mv $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; \
fi
@rm -f $(ASTTOPDIR)/include/asterisk/build.h.tmp
@$(CC) -c -o buildinfo.o $(ASTCFLAGS) buildinfo.c
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
$(ECHO_PREFIX) echo " [LD] $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) -> $@"
ifneq ($(findstring chan_h323,$(MENUSELECT_CHANNELS)),)
$(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS)
$(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS)
else
$(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS)
$(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS)
endif
$(CMD_PREFIX) $(ASTTOPDIR)/build_tools/strip_nonapi $@ || rm $@
clean::
rm -f asterisk

28
main/asterisk.exports Normal file
View File

@@ -0,0 +1,28 @@
{
global:
ast_*;
_ast_*;
__ast_*;
pbx_*;
astman_*;
ao2_*;
__ao2_*;
option_debug;
option_verbose;
dahdi_chan_name;
dahdi_chan_name_len;
dahdi_chan_mode;
cid_di;
cid_dr;
clidsb;
MD5*;
sched_*;
io_*;
jb_*;
channelreloadreason2txt;
devstate2str;
manager_event;
dialed_interface_info;
local:
*;
};

View File

@@ -128,7 +128,7 @@ static inline struct astobj2 *INTERNAL_OBJ(void *user_data)
#ifndef DEBUG_THREADS
int ao2_lock(void *user_data)
#else
int _ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
int __ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{
struct astobj2 *p = INTERNAL_OBJ(user_data);
@@ -150,7 +150,7 @@ int _ao2_lock(void *user_data, const char *file, const char *func, int line, con
#ifndef DEBUG_THREADS
int ao2_trylock(void *user_data)
#else
int _ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var)
int __ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{
struct astobj2 *p = INTERNAL_OBJ(user_data);
@@ -177,7 +177,7 @@ int _ao2_trylock(void *user_data, const char *file, const char *func, int line,
#ifndef DEBUG_THREADS
int ao2_unlock(void *user_data)
#else
int _ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var)
int __ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{
struct astobj2 *p = INTERNAL_OBJ(user_data);

View File

@@ -43,6 +43,8 @@ GC_LDFLAGS=@GC_LDFLAGS@
PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
PTHREAD_LIBS=@PTHREAD_LIBS@
GNU_LD=@GNU_LD@
prefix = @prefix@
exec_prefix = @exec_prefix@

33
res/res_adsi.exports Normal file
View File

@@ -0,0 +1,33 @@
{
global:
ast_adsi_available;
ast_adsi_begin_download;
ast_adsi_channel_restore;
ast_adsi_clear_screen;
ast_adsi_clear_soft_keys;
ast_adsi_connect_session;
ast_adsi_data_mode;
ast_adsi_disconnect_session;
ast_adsi_display;
ast_adsi_download_connect;
ast_adsi_download_disconnect;
ast_adsi_end_download;
ast_adsi_get_cpeid;
ast_adsi_get_cpeinfo;
ast_adsi_input_control;
ast_adsi_input_format;
ast_adsi_load_session;
ast_adsi_load_soft_key;
ast_adsi_print;
ast_adsi_query_cpeid;
ast_adsi_query_cpeinfo;
ast_adsi_read_encoded_dtmf;
ast_adsi_set_keys;
ast_adsi_set_line;
ast_adsi_transmit_message;
ast_adsi_transmit_message_full;
ast_adsi_unload_session;
ast_adsi_voice_mode;
local:
*;
};

7
res/res_agi.exports Normal file
View File

@@ -0,0 +1,7 @@
{
global:
ast_agi_register;
ast_agi_unregister;
local:
*;
};

View File

@@ -558,7 +558,7 @@ static int load_module (void)
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "ODBC Configuration",
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ODBC Configuration",
.load = load_module,
.unload = unload_module,
);

View File

@@ -835,7 +835,7 @@ static int realtime_pgsql_status(int fd, int argc, char **argv)
}
/* needs usecount semantics defined */
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "PostgreSQL RealTime Configuration Driver",
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "PostgreSQL RealTime Configuration Driver",
.load = load_module,
.unload = unload_module,
.reload = reload

View File

@@ -624,7 +624,7 @@ static int unload_module(void)
}
/* needs usecount semantics defined */
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Cryptographic Digital Signatures",
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Cryptographic Digital Signatures",
.load = load_module,
.unload = unload_module,
.reload = reload

13
res/res_features.exports Normal file
View File

@@ -0,0 +1,13 @@
{
global:
ast_bridge_call;
ast_masq_park_call;
ast_park_call;
ast_parking_ext;
ast_pickup_call;
ast_pickup_ext;
ast_register_feature;
ast_unregister_feature;
local:
*;
};

View File

@@ -399,7 +399,7 @@ static int reload(void)
return ind_load_module();
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Indications Resource",
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Indications Resource",
.load = load_module,
.unload = unload_module,
.reload = reload,

13
res/res_jabber.exports Normal file
View File

@@ -0,0 +1,13 @@
{
global:
ast_aji_create_chat;
ast_aji_disconnect;
ast_aji_get_client;
ast_aji_get_clients;
ast_aji_increment_mid;
ast_aji_invite_chat;
ast_aji_join_chat;
ast_aji_send;
local:
*;
};

11
res/res_monitor.exports Normal file
View File

@@ -0,0 +1,11 @@
{
global:
ast_monitor_change_fname;
ast_monitor_pause;
ast_monitor_setjoinfiles;
ast_monitor_start;
ast_monitor_stop;
ast_monitor_unpause;
local:
*;
};

View File

@@ -1486,7 +1486,7 @@ static int unload_module(void)
return res;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Music On Hold Resource",
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Music On Hold Resource",
.load = load_module,
.unload = unload_module,
.reload = reload,

11
res/res_odbc.exports Normal file
View File

@@ -0,0 +1,11 @@
{
global:
ast_odbc_backslash_is_escape;
ast_odbc_prepare_and_execute;
ast_odbc_release_obj;
ast_odbc_request_obj;
ast_odbc_sanity_check;
ast_odbc_smart_execute;
local:
*;
};

18
res/res_smdi.exports Normal file
View File

@@ -0,0 +1,18 @@
{
global:
ast_smdi_interface_find;
ast_smdi_interface_unref;
ast_smdi_md_message_destroy;
ast_smdi_md_message_pop;
ast_smdi_md_message_putback;
ast_smdi_md_message_wait;
ast_smdi_mwi_message_destroy;
ast_smdi_mwi_message_pop;
ast_smdi_mwi_message_putback;
ast_smdi_mwi_message_wait;
ast_smdi_mwi_message_wait_station;
ast_smdi_mwi_set;
ast_smdi_mwi_unset;
local:
*;
};

View File

@@ -109,7 +109,7 @@ static int unload_module(void)
return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "SNMP [Sub]Agent for Asterisk",
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SNMP [Sub]Agent for Asterisk",
.load = load_module,
.unload = unload_module,
);

21
res/res_speech.exports Normal file
View File

@@ -0,0 +1,21 @@
{
global:
ast_speech_change;
ast_speech_change_results_type;
ast_speech_change_state;
ast_speech_destroy;
ast_speech_dtmf;
ast_speech_grammar_activate;
ast_speech_grammar_deactivate;
ast_speech_grammar_load;
ast_speech_grammar_unload;
ast_speech_new;
ast_speech_register;
ast_speech_results_free;
ast_speech_results_get;
ast_speech_start;
ast_speech_unregister;
ast_speech_write;
local:
*;
};