[asterisk-commits] pjproject bundled: Add MALLOC DEBUG capability (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 10 15:21:33 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: pjproject_bundled:  Add MALLOC_DEBUG capability
......................................................................


pjproject_bundled:  Add MALLOC_DEBUG capability

pjproject_bundled will now use the asterisk memory debugging APIs
if MALLOC_DEBUG is turned on in menuselect.

Because this required stubs for the executable programs and the python
bindings, some Makefile reorganization was needed to properly handle
the dependencies.  As a result, the makefile now individually makes
each of the pjproject libraries separately instead of making them all
in 1 shot.  The only visible change is that there are separate status
lines printed for each library instead oif 1 for all libs.  Also, the
making of the pjproject dependency files was eliminated.  They're not
needed for building unless you're actively modifying pjproject source
files and it makes the build process faster.  Finally, any issues with
parallel builds should be resolved again making the build faster.

Change-Id: Icc5e3d658fbfb00e0a46b44c66dcc2522d5171b0
---
M third-party/Makefile.rules
M third-party/pjproject/.gitignore
M third-party/pjproject/Makefile
A third-party/pjproject/patches/asterisk_malloc_debug.c
A third-party/pjproject/patches/asterisk_malloc_debug.h
M third-party/pjproject/patches/config_site.h
6 files changed, 231 insertions(+), 35 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/third-party/Makefile.rules b/third-party/Makefile.rules
index e633e0e..92e4ebc 100644
--- a/third-party/Makefile.rules
+++ b/third-party/Makefile.rules
@@ -4,7 +4,7 @@
 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 5079dee..6904ebf 100644
--- a/third-party/pjproject/.gitignore
+++ b/third-party/pjproject/.gitignore
@@ -2,3 +2,4 @@
 **.bz2
 build.mak
 pjproject.symbols
+.rebuild_needed
diff --git a/third-party/pjproject/Makefile b/third-party/pjproject/Makefile
index 7349db6..bb98a09 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 @@
 
         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 @@
 
 source/.unpacked: $(TMPDIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
 	$(ECHO_PREFIX) Unpacking $<
-	- at rm -rf source &>/dev/null
-	- at mkdir source &>/dev/null
+	- at rm -rf source >/dev/null 2>&1
+	- at 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 @@
 	$(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 @@
 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/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/src/asterisk_malloc_debug.c: patches/asterisk_malloc_debug.c
+	$(ECHO_PREFIX) Copying $< to $@
+	$(CMD_PREFIX) cp -f $< $@
 
-source/pjsip-apps/src/python/build/_pjsua.so: source/pjlib/lib/libpj-$(TARGET_NAME).a
+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/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
+
+$(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 @@
 	$(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 @@
 
 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 0000000..c41767b
--- /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 at 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 0000000..44c4737
--- /dev/null
+++ b/third-party/pjproject/patches/asterisk_malloc_debug.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 George Joseph <gjoseph at 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 f9f76dc..0694f12 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

-- 
To view, visit https://gerrit.asterisk.org/4030
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Icc5e3d658fbfb00e0a46b44c66dcc2522d5171b0
Gerrit-PatchSet: 6
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-commits mailing list