2012-05-21 15:12:37 +04:00
|
|
|
dnl This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
dnl License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2012-02-16 18:53:08 +04:00
|
|
|
dnl Add compiler specific options
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
dnl ============================================================================
|
|
|
|
dnl C++ rtti
|
|
|
|
dnl We don't use it in the code, but it can be usefull for debugging, so give
|
|
|
|
dnl the user the option of enabling it.
|
|
|
|
dnl ============================================================================
|
|
|
|
AC_DEFUN([MOZ_RTTI],
|
|
|
|
[
|
|
|
|
MOZ_ARG_ENABLE_BOOL(cpp-rtti,
|
|
|
|
[ --enable-cpp-rtti Enable C++ RTTI ],
|
|
|
|
[ _MOZ_USE_RTTI=1 ],
|
|
|
|
[ _MOZ_USE_RTTI= ])
|
|
|
|
|
|
|
|
if test -z "$_MOZ_USE_RTTI"; then
|
|
|
|
if test "$GNU_CC"; then
|
|
|
|
CXXFLAGS="$CXXFLAGS -fno-rtti"
|
|
|
|
else
|
|
|
|
case "$target" in
|
|
|
|
*-mingw*)
|
|
|
|
CXXFLAGS="$CXXFLAGS -GR-"
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
])
|
|
|
|
|
2013-08-30 06:10:33 +04:00
|
|
|
dnl ========================================================
|
|
|
|
dnl =
|
|
|
|
dnl = Debugging Options
|
|
|
|
dnl =
|
|
|
|
dnl ========================================================
|
|
|
|
AC_DEFUN([MOZ_DEBUGGING_OPTS],
|
|
|
|
[
|
|
|
|
|
2014-10-16 17:13:27 +04:00
|
|
|
if test -z "$MOZ_DEBUG" -o -n "$MOZ_ASAN"; then
|
2014-05-30 04:39:44 +04:00
|
|
|
MOZ_NO_DEBUG_RTL=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
AC_SUBST(MOZ_NO_DEBUG_RTL)
|
|
|
|
|
2017-03-21 01:25:55 +03:00
|
|
|
MOZ_DEBUG_ENABLE_DEFS="DEBUG"
|
2013-08-30 06:10:33 +04:00
|
|
|
MOZ_ARG_WITH_STRING(debug-label,
|
|
|
|
[ --with-debug-label=LABELS
|
|
|
|
Define DEBUG_<value> for each comma-separated
|
|
|
|
value given.],
|
|
|
|
[ for option in `echo $withval | sed 's/,/ /g'`; do
|
2015-12-29 10:46:09 +03:00
|
|
|
MOZ_DEBUG_ENABLE_DEFS="$MOZ_DEBUG_ENABLE_DEFS DEBUG_${option}"
|
2013-08-30 06:10:33 +04:00
|
|
|
done])
|
|
|
|
|
|
|
|
if test -n "$MOZ_DEBUG"; then
|
2016-07-28 01:14:52 +03:00
|
|
|
if test -n "$COMPILE_ENVIRONMENT"; then
|
|
|
|
AC_MSG_CHECKING([for valid debug flags])
|
|
|
|
_SAVE_CFLAGS=$CFLAGS
|
|
|
|
CFLAGS="$CFLAGS $MOZ_DEBUG_FLAGS"
|
|
|
|
AC_TRY_COMPILE([#include <stdio.h>],
|
|
|
|
[printf("Hello World\n");],
|
|
|
|
_results=yes,
|
|
|
|
_results=no)
|
|
|
|
AC_MSG_RESULT([$_results])
|
|
|
|
if test "$_results" = "no"; then
|
|
|
|
AC_MSG_ERROR([These compiler flags are invalid: $MOZ_DEBUG_FLAGS])
|
|
|
|
fi
|
|
|
|
CFLAGS=$_SAVE_CFLAGS
|
2013-08-30 06:10:33 +04:00
|
|
|
fi
|
2015-09-30 10:33:04 +03:00
|
|
|
|
|
|
|
MOZ_DEBUG_DEFINES="$MOZ_DEBUG_ENABLE_DEFS"
|
|
|
|
else
|
2015-12-29 10:46:09 +03:00
|
|
|
MOZ_DEBUG_DEFINES="NDEBUG TRIMMED"
|
2013-08-30 06:10:33 +04:00
|
|
|
fi
|
|
|
|
|
2015-12-29 10:46:09 +03:00
|
|
|
AC_SUBST_LIST(MOZ_DEBUG_DEFINES)
|
2015-09-30 10:33:04 +03:00
|
|
|
|
2013-08-30 06:10:33 +04:00
|
|
|
])
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
dnl A high level macro for selecting compiler options.
|
2012-02-16 18:53:08 +04:00
|
|
|
AC_DEFUN([MOZ_COMPILER_OPTS],
|
|
|
|
[
|
2013-08-15 18:45:09 +04:00
|
|
|
MOZ_DEBUGGING_OPTS
|
2012-06-11 03:44:50 +04:00
|
|
|
MOZ_RTTI
|
2012-02-16 18:53:08 +04:00
|
|
|
if test "$CLANG_CXX"; then
|
|
|
|
## We disable return-type-c-linkage because jsval is defined as a C++ type but is
|
|
|
|
## returned by C functions. This is possible because we use knowledge about the ABI
|
|
|
|
## to typedef it to a C type with the same layout when the headers are included
|
|
|
|
## from C.
|
2014-06-19 22:42:19 +04:00
|
|
|
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage"
|
2012-02-16 18:53:08 +04:00
|
|
|
fi
|
|
|
|
|
2012-02-27 19:35:44 +04:00
|
|
|
if test "$GNU_CC"; then
|
2013-08-15 18:45:10 +04:00
|
|
|
if test -z "$DEVELOPER_OPTIONS"; then
|
|
|
|
CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
|
|
|
|
CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections"
|
2018-05-04 18:33:25 +03:00
|
|
|
fi
|
2018-03-07 01:40:38 +03:00
|
|
|
|
2018-05-04 18:33:25 +03:00
|
|
|
# For MinGW, we need big-obj otherwise we create too many sections in Unified builds
|
|
|
|
if test "${OS_ARCH}" = "WINNT"; then
|
|
|
|
CFLAGS="$CFLAGS -Wa,-mbig-obj"
|
|
|
|
CXXFLAGS="$CXXFLAGS -Wa,-mbig-obj"
|
2013-08-15 18:45:10 +04:00
|
|
|
fi
|
2018-05-04 18:33:25 +03:00
|
|
|
|
2013-09-03 04:21:21 +04:00
|
|
|
CFLAGS="$CFLAGS -fno-math-errno"
|
|
|
|
CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-math-errno"
|
2012-02-27 19:35:44 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
dnl ========================================================
|
|
|
|
dnl = Identical Code Folding
|
|
|
|
dnl ========================================================
|
|
|
|
|
|
|
|
MOZ_ARG_DISABLE_BOOL(icf,
|
|
|
|
[ --disable-icf Disable Identical Code Folding],
|
|
|
|
MOZ_DISABLE_ICF=1,
|
|
|
|
MOZ_DISABLE_ICF= )
|
|
|
|
|
2013-08-15 18:45:10 +04:00
|
|
|
if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF" -a -z "$DEVELOPER_OPTIONS"; then
|
2012-02-27 19:35:44 +04:00
|
|
|
AC_CACHE_CHECK([whether the linker supports Identical Code Folding],
|
|
|
|
LD_SUPPORTS_ICF,
|
|
|
|
[echo 'int foo() {return 42;}' \
|
|
|
|
'int bar() {return 42;}' \
|
|
|
|
'int main() {return foo() - bar();}' > conftest.${ac_ext}
|
|
|
|
# If the linker supports ICF, foo and bar symbols will have
|
|
|
|
# the same address
|
|
|
|
if AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS -Wl,--icf=safe -ffunction-sections conftest.${ac_ext} $LIBS 1>&2]) &&
|
|
|
|
test -s conftest${ac_exeext} &&
|
2019-01-26 22:12:33 +03:00
|
|
|
objdump -t conftest${ac_exeext} | awk changequote(<<, >>)'{a[<<$>>6] = <<$>>1} END {if (a["foo"] && (a["foo"] != a["bar"])) { exit 1 }}'changequote([, ]); then
|
2012-02-27 19:35:44 +04:00
|
|
|
LD_SUPPORTS_ICF=yes
|
|
|
|
else
|
|
|
|
LD_SUPPORTS_ICF=no
|
|
|
|
fi
|
|
|
|
rm -rf conftest*])
|
|
|
|
if test "$LD_SUPPORTS_ICF" = yes; then
|
2012-03-08 11:56:28 +04:00
|
|
|
_SAVE_LDFLAGS="$LDFLAGS -Wl,--icf=safe"
|
|
|
|
LDFLAGS="$LDFLAGS -Wl,--icf=safe -Wl,--print-icf-sections"
|
|
|
|
AC_TRY_LINK([], [],
|
|
|
|
[LD_PRINT_ICF_SECTIONS=-Wl,--print-icf-sections],
|
|
|
|
[LD_PRINT_ICF_SECTIONS=])
|
|
|
|
AC_SUBST([LD_PRINT_ICF_SECTIONS])
|
|
|
|
LDFLAGS="$_SAVE_LDFLAGS"
|
2012-02-27 19:35:44 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
dnl ========================================================
|
|
|
|
dnl = Automatically remove dead symbols
|
|
|
|
dnl ========================================================
|
|
|
|
|
2013-08-15 18:45:10 +04:00
|
|
|
if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$DEVELOPER_OPTIONS"; then
|
2013-06-27 21:50:54 +04:00
|
|
|
if test -n "$MOZ_DEBUG_FLAGS"; then
|
|
|
|
dnl See bug 670659
|
|
|
|
AC_CACHE_CHECK([whether removing dead symbols breaks debugging],
|
|
|
|
GC_SECTIONS_BREAKS_DEBUG_RANGES,
|
|
|
|
[echo 'int foo() {return 42;}' \
|
|
|
|
'int bar() {return 1;}' \
|
|
|
|
'int main() {return foo();}' > conftest.${ac_ext}
|
|
|
|
if AC_TRY_COMMAND([${CC-cc} -o conftest.${ac_objext} $CFLAGS $MOZ_DEBUG_FLAGS -c conftest.${ac_ext} 1>&2]) &&
|
|
|
|
AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS $MOZ_DEBUG_FLAGS -Wl,--gc-sections conftest.${ac_objext} $LIBS 1>&2]) &&
|
|
|
|
test -s conftest${ac_exeext} -a -s conftest.${ac_objext}; then
|
2013-12-17 06:13:08 +04:00
|
|
|
if test "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest.${ac_objext} conftest.${ac_ext}`" = \
|
|
|
|
"`$PYTHON -m mozbuild.configure.check_debug_ranges conftest${ac_exeext} conftest.${ac_ext}`"; then
|
2013-06-27 21:50:54 +04:00
|
|
|
GC_SECTIONS_BREAKS_DEBUG_RANGES=no
|
|
|
|
else
|
|
|
|
GC_SECTIONS_BREAKS_DEBUG_RANGES=yes
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
dnl We really don't expect to get here, but just in case
|
|
|
|
GC_SECTIONS_BREAKS_DEBUG_RANGES="no, but it's broken in some other way"
|
|
|
|
fi
|
|
|
|
rm -rf conftest*])
|
|
|
|
if test "$GC_SECTIONS_BREAKS_DEBUG_RANGES" = no; then
|
|
|
|
DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
|
|
|
|
fi
|
|
|
|
else
|
2012-02-27 19:35:44 +04:00
|
|
|
DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
|
|
|
|
fi
|
|
|
|
fi
|
2014-09-26 02:33:56 +04:00
|
|
|
|
Bug 1079662 - Always enable PIE. r=froydnj
Last attempt, a few years ago, blatantly failed because nautilus (the
GNOME file manager) can't start PIE executables, which look like shared
libraries, and that it thus considers not being executables.
Downstreams don't actually have the problem, because users won't be
launching Firefox from a file manager, but for mozilla.org builds, it is
a problem because users would download, then extract, and then likely
try to run the Firefox executable from a file manager.
So for mozilla.org builds, we still need to find a way around the
nautilus problem.
A .desktop file could be a solution, but .desktop files have not
actually been designed for this use case, which leads to:
- having to use an awful one-liner shell wrapper to derive the path
to the executable from that of the .desktop file,
- not even being able to associate an icon,
- the .desktop file not being copiable to a location where .desktop
files would normally go, because it would then fail to find the
executable.
Another possibility is to go back to using a shell wrapper, but that's
not entirely appealing.
What we chose here is similar, where we have a small `firefox` wrapper
that launches the real `firefox-bin` (which is still leftover from those
old times where we had a shell wrapper, for reasons).
The small `firefox` wrapper is a minimalist C executable that just
finds the path to the `firefox-bin` executable and executes it with the
same args it was called with. The wrapper is only enabled when the
MOZ_NO_PIE_COMPAT environment variable is set, which we only take into
account on Linux. The variable is only really meant to be used for
mozilla.org builds, for the nautilus problem. Downstreams will just pick
the default, which is changed to build PIE.
On other platforms, PIE was already enabled by default, so we just
remove the --enable-pie configure flag.
Differential Revision: https://phabricator.services.mozilla.com/D5109
2018-09-06 07:27:49 +03:00
|
|
|
if test "$GNU_CC$CLANG_CC"; then
|
|
|
|
MOZ_PROGRAM_LDFLAGS="$MOZ_PROGRAM_LDFLAGS -pie"
|
2014-09-26 02:33:56 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
AC_SUBST(MOZ_PROGRAM_LDFLAGS)
|
|
|
|
|
2015-07-24 11:08:01 +03:00
|
|
|
dnl ASan assumes no symbols are being interposed, and when that happens,
|
|
|
|
dnl it's not happy with it. Unconveniently, since Firefox is exporting
|
|
|
|
dnl libffi symbols and Gtk+3 pulls system libffi via libwayland-client,
|
|
|
|
dnl system libffi interposes libffi symbols that ASan assumes are in
|
|
|
|
dnl libxul, so it barfs about buffer overflows.
|
|
|
|
dnl Using -Wl,-Bsymbolic ensures no exported symbol can be interposed.
|
|
|
|
if test -n "$GCC_USE_GNU_LD"; then
|
|
|
|
case "$LDFLAGS" in
|
|
|
|
*-fsanitize=address*)
|
|
|
|
LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2012-02-27 19:35:44 +04:00
|
|
|
])
|