summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzuul <zuul@gerrit.asterisk.org>2016-10-10 15:21:33 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-10-10 15:21:33 -0500
commitf2e392a3d26aec3fe647b887e813f81b811a8bbe (patch)
treed174519ee05c701f6e90b291c10619df7ac35409
parent9da3489d247775fb06bee40fe4cf26640681fb93 (diff)
parent0dc0356e39e19b480db4549b892f775d105ae8e0 (diff)
Merge "pjproject_bundled: Add MALLOC_DEBUG capability" into 13
-rw-r--r--third-party/Makefile.rules2
-rw-r--r--third-party/pjproject/.gitignore1
-rw-r--r--third-party/pjproject/Makefile105
-rw-r--r--third-party/pjproject/patches/asterisk_malloc_debug.c72
-rw-r--r--third-party/pjproject/patches/asterisk_malloc_debug.h78
-rw-r--r--third-party/pjproject/patches/config_site.h8
6 files changed, 231 insertions, 35 deletions
diff --git a/third-party/Makefile.rules b/third-party/Makefile.rules
index e633e0e98..92e4ebc85 100644
--- a/third-party/Makefile.rules
+++ b/third-party/Makefile.rules
@@ -4,7 +4,7 @@ SUBMAKE?=$(MAKE) --quiet --no-print-directory
ECHO_PREFIX?=@
CMD_PREFIX?=@
QUIET_CONFIGURE=-q
-REALLY_QUIET=&>/dev/null
+REALLY_QUIET=>/dev/null 2>&1
else
SUBMAKE?=$(MAKE)
ECHO_PREFIX?=@\#
diff --git a/third-party/pjproject/.gitignore b/third-party/pjproject/.gitignore
index 5079deeb3..6904ebfb6 100644
--- a/third-party/pjproject/.gitignore
+++ b/third-party/pjproject/.gitignore
@@ -2,3 +2,4 @@ source/
**.bz2
build.mak
pjproject.symbols
+.rebuild_needed
diff --git a/third-party/pjproject/Makefile b/third-party/pjproject/Makefile
index 7349db62f..bb98a09e3 100644
--- a/third-party/pjproject/Makefile
+++ b/third-party/pjproject/Makefile
@@ -1,4 +1,3 @@
-.SUFFIXES:
.PHONY: _all all _install install clean distclean echo_cflags configure
include ../versions.mak
@@ -40,18 +39,28 @@ ifeq ($(SPECIAL_TARGETS),)
include ../../Makefile.rules
include Makefile.rules
- include build.mak
+ include source/user.mak
+ include source/build.mak
CF := $(filter-out -W%,$(CC_CFLAGS))
CF := $(filter-out -I%,$(CF))
- export CFLAGS += $(CF)
- export LDFLAGS += $(CC_LDFLAGS)
- TARGETS := pjproject.symbols
ifeq ($(findstring TEST_FRAMEWORK,$(MENUSELECT_CFLAGS)),TEST_FRAMEWORK)
- TARGETS += source/pjsip-apps/bin/pjsua-$(TARGET_NAME)
+ apps := source/pjsip-apps/bin/pjsua-$(TARGET_NAME) source/pjsip-apps/bin/pjsystest-$(TARGET_NAME)
+ TARGETS += $(apps)
ifneq ($(PYTHONDEV_LIB),)
- TARGETS += source/pjsip-apps/src/python/build/_pjsua.so
+ TARGETS += source/pjsip-apps/src/python/_pjsua.so
endif
endif
+ ifeq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),MALLOC_DEBUG)
+ CF += -DMALLOC_DEBUG
+ MALLOC_DEBUG = yes
+ $(apps): export LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
+ $(apps): source/pjsip-apps/lib/libasterisk_malloc_debug.a
+ source/pjsip-apps/src/python/_pjsua.so: LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
+ source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/lib/libasterisk_malloc_debug.a
+ endif
+ TARGETS += pjproject.symbols
+ export CFLAGS += $(CF)
+ export LDFLAGS += $(CC_LDFLAGS)
else
all install:
endif
@@ -73,8 +82,8 @@ $(TMPDIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2 : ../versions.mak
source/.unpacked: $(TMPDIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
$(ECHO_PREFIX) Unpacking $<
- -@rm -rf source &>/dev/null
- -@mkdir source &>/dev/null
+ -@rm -rf source >/dev/null 2>&1
+ -@mkdir source >/dev/null 2>&1
$(CMD_PREFIX) tar --strip-components=1 -C source -xjf $<
$(ECHO_PREFIX) Applying patches
$(CMD_PREFIX) ./apply_patches $(QUIET_CONFIGURE) ./patches ./source
@@ -84,11 +93,11 @@ source/user.mak: source/.unpacked ./patches/user.mak
$(ECHO_PREFIX) Applying user.mak
$(CMD_PREFIX) cp -f ./patches/user.mak ./source/
-source/pjlib/include/pj/config_site.h: source/.unpacked ./patches/config_site.h
- $(ECHO_PREFIX) Applying config_site.h
- $(CMD_PREFIX) cp -f ./patches/config_site.h ./source/pjlib/include/pj/
+source/pjlib/include/pj/%.h : ./patches/%.h
+ $(ECHO_PREFIX) Applying custom include file $<
+ $(CMD_PREFIX) cp -f $< ./source/pjlib/include/pj/
-build.mak: source/.unpacked source/pjlib/include/pj/config_site.h source/user.mak Makefile.rules
+build.mak: source/.unpacked $(addprefix source/pjlib/include/pj/,$(notdir $(wildcard ./patches/*.h))) source/user.mak Makefile.rules
$(ECHO_PREFIX) Configuring with $(PJPROJECT_CONFIG_OPTS)
$(CMD_PREFIX) (cd source ; autoconf aconfigure.ac > aconfigure && ./aconfigure $(QUIET_CONFIGURE) $(PJPROJECT_CONFIG_OPTS))
@sed -r -e "/prefix|export PJ_SHARED_LIBRARIES|MACHINE_NAME|OS_NAME|HOST_NAME|CC_NAME|CROSS_COMPILE|LINUX_POLL/d" source/build.mak > build.mak
@@ -98,29 +107,53 @@ configure: build.mak
echo_cflags: build.mak
@echo $(PJ_CFLAGS)
-source/pjlib/build/.pjlib-$(TARGET_NAME).depend: build.mak
- $(ECHO_PREFIX) "Making dependencies"
- +$(CMD_PREFIX) $(SUBMAKE) -C source dep
+.rebuild_needed: ../../menuselect.makeopts
+ $(ECHO_PREFIX) Rebuilding
+ $(CMD_PREFIX)$(MAKE) clean $(REALLY_QUIET)
+ @touch .rebuild_needed
-menuselect: ../../menuselect.makeopts ../../makeopts
- -$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build) || :
- -$(CMD_PREFIX) rm -rf pjproject.symbols
+libpj%.a: .rebuild_needed build.mak
+ $(ECHO_PREFIX) Compiling lib $(@F)
+ $(CMD_PREFIX)$(MAKE) -C $(dir $(shell dirname $@))/build $(@F) $(REALLY_QUIET)
-source/pjlib/lib/libpj-$(TARGET_NAME).a: menuselect source/pjlib/build/.pjlib-$(TARGET_NAME).depend
- $(ECHO_PREFIX) Compiling libs
- +$(CMD_PREFIX) $(SUBMAKE) -C source lib $(REALLY_QUIET)
+# We need to compile pjlib, then pjlib-util, then the rest
+# so we separate them out and create the dependencies
+PJLIB_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpj-,$(lib)),$(lib),))
+PJLIB_UTIL_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpjlib-util,$(lib)),$(lib),))
+LIB_FILES = $(filter-out $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES),$(PJ_LIB_FILES))
+ALL_LIB_FILES = $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES) $(LIB_FILES)
-pjproject.symbols: source/pjlib/lib/libpj-$(TARGET_NAME).a
+$(PJLIB_UTIL_LIB_FILES): $(PJLIB_LIB_FILES)
+$(LIB_FILES): $(PJLIB_UTIL_LIB_FILES)
+
+pjproject.symbols: $(ALL_LIB_FILES)
$(ECHO_PREFIX) Generating symbols
- $(CMD_PREFIX) nm -Pog $(PJ_LIB_FILES) | sed -n -r -e "s/.+: ([pP][jJ][^ ]+) .+/\1/gp" | sort -u > pjproject.symbols
+ $(CMD_PREFIX) nm -Pog $(ALL_LIB_FILES) | sed -n -r -e "s/.+: ([pP][jJ][^ ]+) .+/\1/gp" | sort -u > pjproject.symbols
+
+source/pjsip-apps/src/asterisk_malloc_debug.c: patches/asterisk_malloc_debug.c
+ $(ECHO_PREFIX) Copying $< to $@
+ $(CMD_PREFIX) cp -f $< $@
+
+source/pjsip-apps/lib/asterisk_malloc_debug.o: source/pjsip-apps/src/asterisk_malloc_debug.c .rebuild_needed
+ $(ECHO_PREFIX) Compiling asterisk debug malloc stubs
+ $(CMD_PREFIX) $(CC) -fPIC $(PJ_CFLAGS) -c $< -o $@
-source/pjsip-apps/bin/pjsua-$(TARGET_NAME): source/pjlib/lib/libpj-$(TARGET_NAME).a
- $(ECHO_PREFIX) Compiling apps
- $(CMD_PREFIX) $(SUBMAKE) -C source/pjsip-apps/build pjsua pjsystest $(REALLY_QUIET)
+source/pjsip-apps/lib/libasterisk_malloc_debug.a: source/pjsip-apps/lib/asterisk_malloc_debug.o
+ $(ECHO_PREFIX) Creating archive $(@F)
+ $(CMD_PREFIX) ar qs $@ $< >/dev/null 2>&1
-source/pjsip-apps/src/python/build/_pjsua.so: source/pjlib/lib/libpj-$(TARGET_NAME).a
+$(apps): APP = $(filter pj%,$(subst -, ,$(notdir $@)))
+$(apps): pjproject.symbols
+ $(ECHO_PREFIX) Compiling $(APP)
+ $(CMD_PREFIX) +$(MAKE) -C source/pjsip-apps/build $(filter pj%,$(subst -, ,$(notdir $@))) $(REALLY_QUIET)
+
+source/pjsip-apps/src/python/_pjsua.o: source/pjsip-apps/src/python/_pjsua.c $(apps)
$(ECHO_PREFIX) Compiling python bindings
- $(CMD_PREFIX) (cd source/pjsip-apps/src/python ; MAKE=$(MAKE) python setup.py build --build-platlib=./build $(REALLY_QUIET))
+ $(CMD_PREFIX) $(CC) -o $@ -c $< $(PYTHONDEV_INCLUDE) $(CFLAGS) $(PJ_CFLAGS)
+
+source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/src/python/_pjsua.o
+ $(ECHO_PREFIX) Linking python bindings $(@F)
+ $(CMD_PREFIX) gcc -shared -pthread -o $@ $< $(LDFLAGS) $(PJ_LDFLAGS) $(APP_LDLIBS) $(PYTHONDEV_LIB) $(REALLY_QUIET)
_all: $(TARGETS)
@@ -133,10 +166,10 @@ ifneq ($(findstring source/pjsip-apps/bin/pjsua-$(TARGET_NAME),$(TARGETS)),)
$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsua-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsua"
$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsystest-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsystest"
endif
-ifneq ($(findstring source/pjsip-apps/src/python/build/_pjsua.so,$(TARGETS)),)
+ifneq ($(findstring _pjsua.so,$(TARGETS)),)
$(ECHO_PREFIX) Installing python bindings
- $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/build/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
- $(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/build/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
+ $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
+ $(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
endif
uninstall:
@@ -145,10 +178,14 @@ uninstall:
clean:
$(ECHO_PREFIX) Cleaning
- -$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build ; rm -rf source/pjsip-apps/bin/* ) || :
+ +-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean || : ;\
+ rm -rf source/pjsip-apps/bin/* || : ;\
+ find source -name *.a -delete ;\
+ find source -name *.o -delete ;\
+ find source -name *.so -delete ; ) || :
-$(CMD_PREFIX) rm -rf pjproject.symbols
distclean:
$(ECHO_PREFIX) Distcleaning
- -$(CMD_PREFIX) rm -rf source pjproject.symbols pjproject-*.tar.bz2 build.mak
+ -$(CMD_PREFIX) rm -rf source pjproject.symbols pjproject-*.tar.bz2 build.mak .rebuild_needed
diff --git a/third-party/pjproject/patches/asterisk_malloc_debug.c b/third-party/pjproject/patches/asterisk_malloc_debug.c
new file mode 100644
index 000000000..c41767bd8
--- /dev/null
+++ b/third-party/pjproject/patches/asterisk_malloc_debug.c
@@ -0,0 +1,72 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2016, Digium, Inc
+ *
+ * George Joseph <gjoseph@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
+{
+ va_list ap;
+ int rc = 0;
+
+ va_start(ap, format);
+ rc = vasprintf(strp, format, ap);
+ va_end(ap);
+
+ return rc;
+}
+
+void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
+{
+ return calloc(nmemb, size);
+}
+
+void __ast_free(void *ptr, const char *file, int lineno, const char *func)
+{
+ free(ptr);
+}
+
+void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)
+{
+ return malloc(size);
+}
+
+void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
+{
+ return realloc(ptr, size);
+}
+
+char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)
+{
+ return strdup(s);
+}
+
+char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
+{
+ return strndup(s, n);
+}
+
+int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
+{
+ return vasprintf(strp, format, ap);
+}
+
+
diff --git a/third-party/pjproject/patches/asterisk_malloc_debug.h b/third-party/pjproject/patches/asterisk_malloc_debug.h
new file mode 100644
index 000000000..44c473758
--- /dev/null
+++ b/third-party/pjproject/patches/asterisk_malloc_debug.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 George Joseph <gjoseph@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef ASTERISK_MALLOC_DEBUG_H_
+#define ASTERISK_MALLOC_DEBUG_H_
+
+/* Include these now to prevent them from messing up MALLOC_DEBUG */
+#include <sys/types.h>
+#include <pj/compat/string.h>
+#include <pj/compat/stdarg.h>
+#include <pj/compat/malloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
+ __attribute__((format(printf, 5, 6)));
+void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
+void __ast_free(void *ptr, const char *file, int lineno, const char *func);
+void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
+void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
+char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
+char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
+int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
+ __attribute__((format(printf, 2, 0)));
+
+/* Undefine any macros */
+#undef asprintf
+#undef calloc
+#undef free
+#undef malloc
+#undef realloc
+#undef strdup
+#undef strndup
+#undef vasprintf
+
+ /* Provide our own definitions */
+#define asprintf(a, b, c...) \
+ __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
+
+#define calloc(a,b) \
+ __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define free(a) \
+ __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define malloc(a) \
+ __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define realloc(a,b) \
+ __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define strdup(a) \
+ __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define strndup(a,b) \
+ __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#define vasprintf(a,b,c) \
+ __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ASTERISK_MALLOC_DEBUG_H_ */
diff --git a/third-party/pjproject/patches/config_site.h b/third-party/pjproject/patches/config_site.h
index f9f76dc6c..0694f120e 100644
--- a/third-party/pjproject/patches/config_site.h
+++ b/third-party/pjproject/patches/config_site.h
@@ -5,6 +5,14 @@
#include <sys/select.h>
/*
+ * Since both pjproject and asterisk source files will include config_site.h,
+ * we need to make sure that only pjproject source files include asterisk_malloc_debug.h.
+ */
+#if defined(MALLOC_DEBUG) && !defined(_ASTERISK_ASTMM_H)
+#include "asterisk_malloc_debug.h"
+#endif
+
+/*
* Defining PJMEDIA_HAS_SRTP to 0 does NOT disable Asterisk's ability to use srtp.
* It only disables the pjmedia srtp transport which Asterisk doesn't use.
* The reason for the disable is that while Asterisk works fine with older libsrtp