Bug 892355 - Force enable elfhack with --enable-elf-hack. r=ted,a=bajaj
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 12 Jul 2013 09:15:10 +0900
changeset 285312 0d2724681600a94e5d77269bdbc926482fdd2e3d
parent 285311 2ab705b1fb979d3e6831b9822c9b9d1a28d6c3d9
child 285313 696593313840a20fbb209f0e1ec791439a52d553
push id218
push userryanvm@gmail.com
push dateWed, 16 Dec 2015 22:58:33 +0000
reviewersted, bajaj
bugs892355
milestone24.0a2
Bug 892355 - Force enable elfhack with --enable-elf-hack. r=ted,a=bajaj
build/unix/mozconfig.linux
configure.in
mobile/android/config/mozconfigs/android/nightly
mobile/android/config/mozconfigs/common
--- a/build/unix/mozconfig.linux
+++ b/build/unix/mozconfig.linux
@@ -1,4 +1,6 @@
 . "$topsrcdir/build/mozconfig.common"
 
 CC="/tools/gcc-4.7.2-0moz1/bin/gcc"
 CXX="/tools/gcc-4.7.2-0moz1/bin/g++"
+
+ac_add_options --enable-elf-hack
--- a/configure.in
+++ b/configure.in
@@ -7525,23 +7525,26 @@ MOZ_ARG_ENABLE_BOOL(elf-dynstr-gc,
 
 dnl ========================================================
 dnl = --disable-elf-hack
 dnl ========================================================
 
 USE_ELF_HACK=1
 MOZ_ARG_DISABLE_BOOL(elf-hack,
 [  --disable-elf-hack      Disable elf hacks],
-    USE_ELF_HACK=,
-    USE_ELF_HACK=1)
+    [USE_ELF_HACK=],
+    [USE_ELF_HACK=F # Force enable elf-hack])
 
 # Disable elf hack for profiling because the built in profiler
 # doesn't read the segments properly with elf hack. This is
 # temporary and should be fixed soon in the profiler.
 if test "$MOZ_PROFILING" = 1; then
+  if test "$USE_ELF_HACK" = F; then
+    AC_ERROR([--enable-elf-hack is not compatible with --enable-profiling])
+  fi
   USE_ELF_HACK=
 fi
 
 # Only enable elfhack where supported
 if test "$USE_ELF_HACK" = 1; then
     case "${HOST_OS_ARCH},${OS_ARCH}" in
     Linux,Linux)
         case "${CPU_ARCH}" in
@@ -7554,43 +7557,54 @@ if test "$USE_ELF_HACK" = 1; then
         esac
         ;;
     *)
         USE_ELF_HACK=
         ;;
     esac
 fi
 
-if test "$USE_ELF_HACK" = 1; then
+if test -n "$USE_ELF_HACK"; then
     dnl PT_GNU_RELRO segment makes the dynamic linker set a read-only flag on
     dnl memory addresses it maps to. The result is that by the time elfhack
     dnl kicks in, it is not possible to apply relocations because of that,
     dnl thus elfhack effectively skips relocations inside the PT_GNU_RELRO
     dnl segment. It makes elfhack mostly useless, so considering the problems
     dnl we have we PT_GNU_RELRO (e.g. bug 664366), and until elfhack can deal
     dnl with PT_GNU_RELRO segments, it's just simpler to disable elfhack when
-    dnl the linker creates PT_GNU_RELRO segments.
+    dnl the linker creates PT_GNU_RELRO segments. However, when we do want
+    dnl elfhack enabled, disable PT_GNU_RELRO instead.
     AC_CACHE_CHECK([whether linker creates PT_GNU_RELRO segments],
         LINK_WITH_PT_GNU_RELRO,
         [echo "int main() {return 0;}" > conftest.${ac_ext}
          if AC_TRY_COMMAND(${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.${ac_ext} $LIBS 1>&2) &&
             test -s conftest${ac_exeext}; then
             if ${TOOLCHAIN_PREFIX}readelf -l conftest${ac_exeext} | grep GNU_RELRO > /dev/null; then
                 LINK_WITH_PT_GNU_RELRO=yes
             else
                 LINK_WITH_PT_GNU_RELRO=no
             fi
          else
              dnl We really don't expect to get here, but just in case
              AC_ERROR([couldn't compile a simple C file])
          fi
          rm -rf conftest*])
     if test "$LINK_WITH_PT_GNU_RELRO" = yes; then
-        AC_MSG_WARN([Disabling elfhack])
-        USE_ELF_HACK=
+        if test "$USE_ELF_HACK" = F; then
+            AC_MSG_CHECKING([for -z norelro option to ld])
+            _SAVE_LDFLAGS=$LDFLAGS
+            LDFLAGS="$LDFLAGS -Wl,-z,norelro"
+            AC_TRY_LINK(,,AC_MSG_RESULT([yes])
+                        [NSPR_LDFLAGS="$NSPR_LDFLAGS -Wl,-z,norelro"],
+                        AC_ERROR([--enable-elf-hack is not compatible with a linker creating a PT_GNU_RELRO segment and that doesn't support the "-z norelro" option.]))
+            USE_ELF_HACK=1
+        else
+            AC_MSG_WARN([Disabling elfhack])
+            USE_ELF_HACK=
+        fi
     fi
 fi
 
 dnl ========================================================
 dnl = libstdc++ compatibility hacks
 dnl ========================================================
 
 STDCXX_COMPAT=
--- a/mobile/android/config/mozconfigs/android/nightly
+++ b/mobile/android/config/mozconfigs/android/nightly
@@ -14,16 +14,17 @@ else
   ac_add_options --with-android-sdk="/tools/android-sdk-r16/platforms/android-16"
 fi
 
 ac_add_options --with-android-gnu-compiler-version=4.7
 ac_add_options --with-android-version=9
 ac_add_options --with-system-zlib
 ac_add_options --enable-update-channel=${MOZ_UPDATE_CHANNEL}
 ac_add_options --enable-profiling
+ac_add_options --disable-elf-hack # --enable-elf-hack conflicts with --enable-profiling
 
 export JAVA_HOME=/tools/jdk6
 export MOZILLA_OFFICIAL=1
 export MOZ_TELEMETRY_REPORTING=1
 
 ac_add_options --with-branding=mobile/android/branding/aurora
 
 # Treat warnings as errors in directories with FAIL_ON_WARNINGS.
--- a/mobile/android/config/mozconfigs/common
+++ b/mobile/android/config/mozconfigs/common
@@ -5,8 +5,10 @@
 # This file is included at the top of all native android mozconfigs
 
 . "$topsrcdir/build/mozconfig.common"
 
 # Set the most aggressive settings for szip. Not the default because it's
 # much slower and we didn't want to slow down developers builds.
 # Has no effect when MOZ_ENABLE_SZIP is not set in mobile/android/confvars.sh.
 MOZ_SZIP_FLAGS="-D auto -f auto"
+
+ac_add_options --enable-elf-hack