Bug 1698706 - Always add PIC flags to C{,XX}FLAGS. r=firefox-build-system-reviewers,andi,sheehan,mhentges

The build always uses them anyways, but configure tests don't, and some
of them fail as a consequence in some cases (example: when UBsan is
enabled, all AC_LANG_CPLUSPLUS + AC_CHECK_FUNCS tests fail). We also had
similar problems in the past, such as bug 1513605.

By adding the PIC flags to CFLAGS and CXXFLAGS, we ensure old-configure
tests use the flags as well.

While here, we also remove DSO_CFLAGS, which was always empty, and we
stop passing -fPIC to wasm compiles, because it has no effect there.

Differential Revision: https://phabricator.services.mozilla.com/D108560
This commit is contained in:
Mike Hommey 2021-03-17 01:27:39 +00:00
Родитель f6a46d059d
Коммит 473d31abfb
4 изменённых файлов: 9 добавлений и 37 удалений

Просмотреть файл

@ -2760,7 +2760,7 @@ def make_shared_library(target, compiler):
cc = ["$(CC)", "$(COMPUTED_C_LDFLAGS)"]
cxx = ["$(CXX)", "$(COMPUTED_CXX_LDFLAGS)"]
flags = ["$(PGO_CFLAGS)", "$(DSO_PIC_CFLAGS)", "$(DSO_LDOPTS)"]
flags = ["$(PGO_CFLAGS)", "$(DSO_LDOPTS)"]
output = ["-o", "$@"]
if target.kernel == "Darwin":

Просмотреть файл

@ -313,7 +313,6 @@ if test "$GNU_CC"; then
DSO_LDOPTS="$DSO_LDOPTS -Wl,-z,defs"
fi
fi
DSO_CFLAGS=''
if test "$OS_ARCH" != "WINNT"; then
DSO_PIC_CFLAGS='-fPIC'
@ -494,7 +493,6 @@ case "$target" in
;;
*-mingw*)
DSO_CFLAGS=
DSO_PIC_CFLAGS=
if test -n "$GNU_CC" -o -n "$CLANG_CC"; then
# $GNU_CC will match gcc and clang; while $CLANG_CC will match only clang
@ -682,7 +680,6 @@ case "$target" in
;;
*-netbsd*)
DSO_CFLAGS=''
CFLAGS="$CFLAGS -Dunix"
CXXFLAGS="$CXXFLAGS -Dunix"
if $CC -E - -dM </dev/null | grep __ELF__ >/dev/null; then
@ -700,7 +697,6 @@ case "$target" in
;;
*-openbsd*)
DSO_CFLAGS=''
DSO_PIC_CFLAGS='-fPIC'
DSO_LDOPTS='-shared -fPIC'
if test "$LIBRUNPATH"; then
@ -714,6 +710,9 @@ case "$target" in
esac
CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"
CXXFLAGS="$CXXFLAGS $DSO_PIC_CFLAGS"
if test -z "$MOZ_OPTIMIZE_FLAGS"; then
MOZ_OPTIMIZE_FLAGS="-O"
fi
@ -910,9 +909,7 @@ AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC),
ac_cv_clock_monotonic,
[for libs in "" -lrt; do
_SAVE_LIBS="$LIBS"
_SAVE_CFLAGS="$CFLAGS"
LIBS="$LIBS $libs"
CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"
dnl clock_gettime is available on OSX since 10.12, so depending on MACOSX_DEPLOYMENT_TARGET,
dnl we should or not be able to use it. To detect if we can, we need to make the
dnl availability attribute strict, so that compilation fails when the target is < 10.12.
@ -926,7 +923,6 @@ dnl availability attribute strict, so that compilation fails when the target is
break,
ac_cv_clock_monotonic=no)
LIBS="$_SAVE_LIBS"
CFLAGS="$_SAVE_CFLAGS"
done])
if test "$ac_cv_clock_monotonic" != "no"; then
HAVE_CLOCK_MONOTONIC=1
@ -1057,7 +1053,7 @@ fi
# enabled, the linker in xcode 4.1 will crash. Without this it would crash when
# linking XUL.
_SAVE_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $DSO_PIC_CFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
LDFLAGS="$LDFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
AC_CACHE_CHECK(for __thread keyword for TLS variables,
ac_cv_thread_keyword,
[AC_TRY_LINK([__thread bool tlsIsMainThread = false;],
@ -1401,8 +1397,6 @@ AC_SUBST(HOST_BIN_SUFFIX)
AC_SUBST(TARGET_XPCOM_ABI)
AC_SUBST_LIST(DSO_CFLAGS)
AC_SUBST_LIST(DSO_PIC_CFLAGS)
AC_SUBST(DSO_LDOPTS)
AC_SUBST(BIN_SUFFIX)
AC_SUBST(USE_N32)

Просмотреть файл

@ -301,7 +301,6 @@ if test "$GNU_CC"; then
SSE2_FLAGS="-msse2"
SSSE3_FLAGS="-mssse3"
CFLAGS="$CFLAGS -fno-strict-aliasing"
DSO_CFLAGS=''
if test "$OS_ARCH" != "WINNT" -o -z "$CLANG_CC"; then
DSO_PIC_CFLAGS='-fPIC'
@ -586,7 +585,6 @@ case "$target" in
esac
;;
*-mingw*)
DSO_CFLAGS=
DSO_PIC_CFLAGS=
# certain versions of cygwin's makedepend barf on the
# #include <string> vs -I./dist/include/string issue so don't use it
@ -802,7 +800,6 @@ case "$target" in
;;
*-netbsd*)
DSO_CFLAGS=''
CFLAGS="$CFLAGS -Dunix"
CXXFLAGS="$CXXFLAGS -Dunix"
if $CC -E - -dM </dev/null | grep __ELF__ >/dev/null; then
@ -824,7 +821,6 @@ case "$target" in
X11BASE=/usr/X11R6
fi
MOZ_FIX_LINK_PATHS="$MOZ_FIX_LINK_PATHS -Wl,-rpath-link,${X11BASE}/lib"
DSO_CFLAGS=''
DSO_PIC_CFLAGS='-fPIC'
DSO_LDOPTS='-shared -fPIC'
if test "$LIBRUNPATH"; then
@ -838,6 +834,9 @@ case "$target" in
esac
CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"
CXXFLAGS="$CXXFLAGS $DSO_PIC_CFLAGS"
if test -z "$MOZ_OPTIMIZE_FLAGS"; then
MOZ_OPTIMIZE_FLAGS="-O"
fi
@ -1139,9 +1138,7 @@ AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC),
ac_cv_clock_monotonic,
[for libs in "" -lrt; do
_SAVE_LIBS="$LIBS"
_SAVE_CFLAGS="$CFLAGS"
LIBS="$LIBS $libs"
CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"
dnl clock_gettime is available on OSX since 10.12, so depending on MACOSX_DEPLOYMENT_TARGET,
dnl we should or not be able to use it. To detect if we can, we need to make the
dnl availability attribute strict, so that compilation fails when the target is < 10.12.
@ -1155,7 +1152,6 @@ dnl availability attribute strict, so that compilation fails when the target is
break,
ac_cv_clock_monotonic=no)
LIBS="$_SAVE_LIBS"
CFLAGS="$_SAVE_CFLAGS"
done])
if test "$ac_cv_clock_monotonic" != "no"; then
HAVE_CLOCK_MONOTONIC=1
@ -1295,7 +1291,7 @@ fi
# enabled, the linker in xcode 4.1 will crash. Without this it would crash when
# linking XUL.
_SAVE_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $DSO_PIC_CFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
LDFLAGS="$LDFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
AC_CACHE_CHECK(for __thread keyword for TLS variables,
ac_cv_thread_keyword,
[AC_TRY_LINK([__thread bool tlsIsMainThread = false;],
@ -2719,8 +2715,6 @@ AC_SUBST(HAVE_TOOLCHAIN_SUPPORT_MSSE4_1)
AC_SUBST(HAVE_X86_AVX2)
AC_SUBST(HAVE_ALTIVEC)
AC_SUBST_LIST(DSO_CFLAGS)
AC_SUBST_LIST(DSO_PIC_CFLAGS)
AC_SUBST(DSO_LDOPTS)
AC_SUBST(BIN_SUFFIX)
AC_SUBST(USE_N32)

Просмотреть файл

@ -602,12 +602,6 @@ class CompileFlags(TargetCompileFlags):
),
("CXXFLAGS", "CFLAGS"),
),
("DSO", context.config.substs.get("DSO_CFLAGS"), ("CXXFLAGS", "CFLAGS")),
(
"DSO_PIC",
context.config.substs.get("DSO_PIC_CFLAGS"),
("CXXFLAGS", "CFLAGS"),
),
("RTL", None, ("CXXFLAGS", "CFLAGS")),
(
"OS_COMPILE_CFLAGS",
@ -718,16 +712,6 @@ class WasmFlags(TargetCompileFlags):
),
("WASM_CXXFLAGS", "WASM_CFLAGS"),
),
(
"DSO",
context.config.substs.get("DSO_CFLAGS"),
("WASM_CXXFLAGS", "WASM_CFLAGS"),
),
(
"DSO_PIC",
context.config.substs.get("DSO_PIC_CFLAGS"),
("WASM_CXXFLAGS", "WASM_CFLAGS"),
),
("RTL", None, ("WASM_CXXFLAGS", "WASM_CFLAGS")),
(
"DEBUG",