Bug 805096 - Better explain why we use __attribute__((weak)). r=glandium.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Wed, 24 Oct 2012 14:33:45 -0400
changeset 111275 1a9187422d0e6eba6d3d4374a33462b4101021f0
parent 111274 fae81f4e7a9b4526af487664c92d176d4716e01f
child 111276 256a32a2b634315673a7266cfcc36f82c43b7f31
push id16980
push userrespindola@mozilla.com
push dateWed, 24 Oct 2012 18:34:59 +0000
treeherdermozilla-inbound@1a9187422d0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs805096
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 805096 - Better explain why we use __attribute__((weak)). r=glandium.
mfbt/Types.h
--- a/mfbt/Types.h
+++ b/mfbt/Types.h
@@ -91,18 +91,21 @@
  * export mfbt declarations when building mfbt, and they expose import mfbt
  * declarations when using mfbt.
  */
 #if defined(IMPL_MFBT)
 #  define MFBT_API(type)        MOZ_EXPORT_API(type)
 #  define MFBT_DATA(type)       MOZ_EXPORT_DATA(type)
 #else
   /*
-   * When mozglue is linked in the program, we need the MFBT API symbols
-   * to be weak.
+   * On linux mozglue is linked in the program and we link libxul.so with
+   * -z,defs. Normally that causes the linker to reject undefined references in
+   * libxul.so, but as a loophole it allows undefined references to weak
+   * symbols. We add the weak attribute to the import version of the MFBT API
+   * macros to exploit this.
    */
 #  if defined(MOZ_GLUE_IN_PROGRAM)
 #    define MFBT_API(type)        __attribute__((weak)) MOZ_IMPORT_API(type)
 #    define MFBT_DATA(type)       __attribute__((weak)) MOZ_IMPORT_DATA(type)
 #  else
 #    define MFBT_API(type)        MOZ_IMPORT_API(type)
 #    define MFBT_DATA(type)       MOZ_IMPORT_DATA(type)
 #  endif