Bug 1360300 -- Support enabling PIE when using clang. draft
authorAlex Gaynor <agaynor@mozilla.com>
Mon, 01 May 2017 15:45:33 -0400
changeset 570977 6f7729143a80c3931bc7d4bdb81db30b5286f466
parent 570886 57b37213d81150642f5139764e7044b07b9dccc3
child 626632 4498feba04894c7caeec15f8f7e184eb750b9793
push id56644
push userbmo:agaynor@mozilla.com
push dateMon, 01 May 2017 20:32:47 +0000
bugs1360300
milestone55.0a1
Bug 1360300 -- Support enabling PIE when using clang. Also remove bits of a comment, now that we support only macOS 10.9+, most of the comment isn't relevant. While PIE is enabled by default on macOS, this isn't true of clang on Linux. --enable-pie can now be used with clang on Linux. r=froydnj MozReview-Commit-ID: rc6zJiWzLo
build/autoconf/compiler-opts.m4
--- a/build/autoconf/compiler-opts.m4
+++ b/build/autoconf/compiler-opts.m4
@@ -246,34 +246,30 @@ if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -
              DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
          fi
     else
         DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
     fi
 fi
 
 # bionic in Android < 4.1 doesn't support PIE
-# On OSX, the linker defaults to building PIE programs when targetting OSX 10.7+,
-# but not when targetting OSX < 10.7. OSX < 10.7 doesn't support running PIE
-# programs, so as long as support for OSX 10.6 is kept, we can't build PIE.
-# Even after dropping 10.6 support, MOZ_PIE would not be useful since it's the
-# default (and clang says the -pie option is not used).
+# On OSX, the linker defaults to building PIE programs when targeting OSX 10.7.
 # On other Unix systems, some file managers (Nautilus) can't start PIE programs
 if test -n "$gonkdir" && test "$ANDROID_VERSION" -ge 16; then
     MOZ_PIE=1
 else
     MOZ_PIE=
 fi
 
 MOZ_ARG_ENABLE_BOOL(pie,
 [  --enable-pie           Enable Position Independent Executables],
     MOZ_PIE=1,
     MOZ_PIE= )
 
-if test "$GNU_CC" -a -n "$MOZ_PIE"; then
+if test "$GNU_CC$CLANG_CC" -a -n "$MOZ_PIE"; then
     AC_MSG_CHECKING([for PIE support])
     _SAVE_LDFLAGS=$LDFLAGS
     LDFLAGS="$LDFLAGS -pie"
     AC_TRY_LINK(,,AC_MSG_RESULT([yes])
                   [MOZ_PROGRAM_LDFLAGS="$MOZ_PROGRAM_LDFLAGS -pie"],
                   AC_MSG_RESULT([no])
                   AC_MSG_ERROR([--enable-pie requires PIE support from the linker.]))
     LDFLAGS=$_SAVE_LDFLAGS