mozilla-jemalloc-symbols.patch
changeset 203 3820fe99f0fe
parent 200 ade149166873
child 205 71411f8585cd
equal deleted inserted replaced
200:ade149166873 203:3820fe99f0fe
     1 # HG changeset patch
       
     2 # User Mike Hommey
       
     3 # Parent 4510a9c913731464c0bc3636cd03d3f7fdb27186
       
     4 Bug 611405 - Export jemalloc symbols when linking with the xpcom standalone glue and avoid crash if symbols are not available for any reason
       
     5 
       
     6 diff --git a/build/unix/gnu-ld-scripts/jemalloc-standalone-linkage-version-script b/build/unix/gnu-ld-scripts/jemalloc-standalone-linkage-version-script
       
     7 new file mode 100644
       
     8 --- /dev/null
       
     9 +++ b/build/unix/gnu-ld-scripts/jemalloc-standalone-linkage-version-script
       
    10 @@ -0,0 +1,19 @@
       
    11 +{
       
    12 +   global:
       
    13 +		_malloc_postfork;
       
    14 +		_malloc_prefork;
       
    15 +		jemalloc_stats;
       
    16 +		malloc_usable_size;
       
    17 +		posix_memalign;
       
    18 +		free;
       
    19 +		realloc;
       
    20 +		calloc;
       
    21 +		malloc;
       
    22 +		memalign;
       
    23 +		valloc;
       
    24 +		__free_hook;
       
    25 +		__malloc_hook;
       
    26 +		__realloc_hook;
       
    27 +		__memalign_hook;
       
    28 +   local: *;
       
    29 +};
       
    30 diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in
       
    31 --- a/config/autoconf.mk.in
       
    32 +++ b/config/autoconf.mk.in
       
    33 @@ -187,16 +187,17 @@ MAKENSISU=@MAKENSISU@
       
    34  RM = rm -f
       
    35  
       
    36  # The MOZ_UI_LOCALE var is used to build a particular locale. Do *not*
       
    37  # use the var to change any binary files. Do *not* use this var unless you
       
    38  # write rules for the "clean-locale" and "locale" targets.
       
    39  MOZ_UI_LOCALE = @MOZ_UI_LOCALE@
       
    40  
       
    41  MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS = @MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS@
       
    42 +MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS = @MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS@
       
    43  MOZ_COMPONENT_NSPR_LIBS=@MOZ_COMPONENT_NSPR_LIBS@
       
    44  
       
    45  MOZ_FIX_LINK_PATHS=@MOZ_FIX_LINK_PATHS@
       
    46  
       
    47  XPCOM_FROZEN_LDOPTS=@XPCOM_FROZEN_LDOPTS@
       
    48  XPCOM_LIBS=@XPCOM_LIBS@
       
    49  LIBXUL_LIBS=@LIBXUL_LIBS@
       
    50  MOZ_TIMELINE=@MOZ_TIMELINE@
       
    51 diff --git a/config/config.mk b/config/config.mk
       
    52 --- a/config/config.mk
       
    53 +++ b/config/config.mk
       
    54 @@ -157,16 +157,21 @@ FINAL_LINK_COMPS = $(DEPTH)/config/final
       
    55  FINAL_LINK_COMP_NAMES = $(DEPTH)/config/final-link-comp-names
       
    56  
       
    57  MOZ_UNICHARUTIL_LIBS = $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFIX)
       
    58  MOZ_WIDGET_SUPPORT_LIBS    = $(DIST)/lib/$(LIB_PREFIX)widgetsupport_s.$(LIB_SUFFIX)
       
    59  
       
    60  ifdef MOZ_MEMORY
       
    61  ifneq (,$(filter-out WINNT WINCE,$(OS_ARCH)))
       
    62  JEMALLOC_LIBS = $(MKSHLIB_FORCE_ALL) $(call EXPAND_MOZLIBNAME,jemalloc) $(MKSHLIB_UNFORCE_ALL)
       
    63 +# If we are linking jemalloc into a program, we want the jemalloc symbols
       
    64 +# to be exported
       
    65 +ifneq (,$(SIMPLE_PROGRAMS)$(PROGRAM))
       
    66 +JEMALLOC_LIBS += $(MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS)
       
    67 +endif
       
    68  endif
       
    69  endif
       
    70  
       
    71  CC := $(CC_WRAPPER) $(CC)
       
    72  CXX := $(CXX_WRAPPER) $(CXX)
       
    73  
       
    74  # determine debug-related options
       
    75  _DEBUG_CFLAGS :=
       
    76 diff --git a/configure.in b/configure.in
       
    77 --- a/configure.in
       
    78 +++ b/configure.in
       
    79 @@ -2892,21 +2892,23 @@ case "$target" in
       
    80      if test -z "$GNU_CC"; then
       
    81          NO_LD_ARCHIVE_FLAGS=
       
    82      fi
       
    83      ;;
       
    84  esac
       
    85  AC_SUBST(NO_LD_ARCHIVE_FLAGS)
       
    86  
       
    87  dnl ========================================================
       
    88 -dnl = Flags to strip unused symbols from .so components
       
    89 +dnl = Flags to strip unused symbols from .so components and
       
    90 +dnl = to export jemalloc symbols when linking a program
       
    91  dnl ========================================================
       
    92  case "$target" in
       
    93      *-linux*|*-kfreebsd*-gnu|*-gnu*)
       
    94          MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,--version-script -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-version-script'
       
    95 +        MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS='-rdynamic -Wl,--version-script -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/jemalloc-standalone-linkage-version-script'
       
    96          ;;
       
    97      *-solaris*)
       
    98          if test -z "$GNU_CC"; then
       
    99           MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-M $(BUILD_TOOLS)/gnu-ld-scripts/components-mapfile'
       
   100          else
       
   101           if test -z "$GCC_USE_GNU_LD"; then
       
   102            MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,-M -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-mapfile'
       
   103           else
       
   104 @@ -8909,16 +8911,17 @@ AC_SUBST(MOZ_USER_DIR)
       
   105  AC_SUBST(MOZ_CRASHREPORTER)
       
   106  AC_SUBST(MOZ_UPDATER)
       
   107  
       
   108  AC_SUBST(ENABLE_STRIP)
       
   109  AC_SUBST(PKG_SKIP_STRIP)
       
   110  AC_SUBST(USE_ELF_DYNSTR_GC)
       
   111  AC_SUBST(INCREMENTAL_LINKER)
       
   112  AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS)
       
   113 +AC_SUBST(MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS)
       
   114  AC_SUBST(MOZ_COMPONENT_NSPR_LIBS)
       
   115  
       
   116  AC_SUBST(MOZ_FIX_LINK_PATHS)
       
   117  AC_SUBST(XPCOM_LIBS)
       
   118  AC_SUBST(XPCOM_FROZEN_LDOPTS)
       
   119  AC_SUBST(XPCOM_GLUE_LDOPTS)
       
   120  AC_SUBST(XPCOM_STANDALONE_GLUE_LDOPTS)
       
   121  
       
   122 diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp
       
   123 --- a/xpcom/base/nsMemoryReporterManager.cpp
       
   124 +++ b/xpcom/base/nsMemoryReporterManager.cpp
       
   125 @@ -54,20 +54,16 @@
       
   126  #    include "jemalloc.h"
       
   127  #  elif defined(XP_LINUX)
       
   128  #    define HAVE_JEMALLOC_STATS 1
       
   129  #    include "jemalloc_types.h"
       
   130  // jemalloc is directly linked into firefox-bin; libxul doesn't link
       
   131  // with it.  So if we tried to use jemalloc_stats directly here, it
       
   132  // wouldn't be defined.  Instead, we don't include the jemalloc header
       
   133  // and weakly link against jemalloc_stats.
       
   134 -//
       
   135 -// NB: we don't null-check this symbol at runtime because we expect it
       
   136 -// to have been resolved.  If it hasn't, the crash jumping to NULL
       
   137 -// will indicate the bug.
       
   138  extern "C" {
       
   139  extern void jemalloc_stats(jemalloc_stats_t* stats)
       
   140    NS_VISIBILITY_DEFAULT __attribute__((weak));
       
   141  }
       
   142  #  endif  // XP_LINUX
       
   143  #endif  // MOZ_MEMORY
       
   144  
       
   145  #if HAVE_JEMALLOC_STATS
       
   146 @@ -214,16 +210,20 @@ NS_MEMORY_REPORTER_IMPLEMENT(Win32Privat
       
   147   ** nsMemoryReporterManager implementation
       
   148   **/
       
   149  
       
   150  NS_IMPL_ISUPPORTS1(nsMemoryReporterManager, nsIMemoryReporterManager)
       
   151  
       
   152  NS_IMETHODIMP
       
   153  nsMemoryReporterManager::Init()
       
   154  {
       
   155 +#if HAVE_JEMALLOC_STATS && defined(XP_LINUX)
       
   156 +    if (!jemalloc_stats)
       
   157 +        return NS_ERROR_FAILURE;
       
   158 +#endif
       
   159      /*
       
   160       * Register our core reporters
       
   161       */
       
   162  #define REGISTER(_x)  RegisterReporter(new NS_MEMORY_REPORTER_NAME(_x))
       
   163  
       
   164      /*
       
   165       * Register our core jemalloc/malloc reporters
       
   166       */