[2/3] Disable _FILE_OFFSET_BITS if the compiler defaults to it

Message ID 20240910122244.1995107-3-adhemerval.zanella@linaro.org
State Committed
Commit 3f1932ed2e6b643848ea7a42f9f15ed80552befb
Delegated to: DJ Delorie
Headers
Series Allow glibc to build with gcc that defaults to fortify, LFS, and 64-bit time_t |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Adhemerval Zanella Netto Sept. 10, 2024, 12:22 p.m. UTC
  Even though building glibc with LFS flags is not supported, and the
the usual way is to patch the build system to avoid it [1]; some system
do enable it by default, and it increases the requirements to build
glibc in such cases (it also does not help newcomers when trying
to build glibc).

The conform namespace and linknamespace tests also do not expect
that flag to be set by default, so disable it as well.

Checked with a build/check for major ABI and some (i386, arm,
mipsel, hppa) with a toolchain that has LFS flags by default.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=31624
---
 Makeconfig       |  3 +++
 configure        | 32 ++++++++++++++++++++++++++++++++
 configure.ac     | 13 +++++++++++++
 conform/Makefile |  2 +-
 4 files changed, 49 insertions(+), 1 deletion(-)
  

Comments

DJ Delorie Sept. 23, 2024, 10:15 p.m. UTC | #1
So the idea is, if the user/compiler provides -D_FILE_OFFSET_BITS, we
pass -U to undo that.  We can't just filter out the -D because it may be
intrinsic to the compiler.

LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>

Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> diff --git a/Makeconfig b/Makeconfig
> +# Filter out LFS flags if compiler defines it by default.
> ++cflags += $(no-file-offset-bits-source)

Ok.

> diff --git a/configure.ac b/configure.ac

> +dnl Check if compiler define _FILE_OFFSET_BITS by default
> +AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[]], [[
> +#ifndef _FILE_OFFSET_BITS
> +# error _FILE_OFFSET_BITS not defined
> +#endif]])],
> +	       [libc_cv_compiler_default_file_offset_bits=yes],
> +	       [libc_cv_compiler_default_file_offset_bits=no])
> +AS_IF([test "$libc_cv_compiler_default_file_offset_bits" = yes],
> +      [no_file_offset_bits_source="-U_FILE_OFFSET_BITS"])
> +AC_SUBST(no_file_offset_bits_source)
> +LIBC_CONFIG_VAR([no-file-offset-bits-source], [$no_file_offset_bits_source])

So if the test passes, that means _FILE_OFFSET_BITS is set, so add the
-U to it.  Ok.

> diff --git a/conform/Makefile b/conform/Makefile
> -conformtest-cc-flags = -I../include $(+sysdep-includes) $(sysincludes) -I..
> +conformtest-cc-flags =  -I../include $(+sysdep-includes) $(sysincludes) -I.. $(no-file-offset-bits-source)

Ok.
  

Patch

diff --git a/Makeconfig b/Makeconfig
index a87ff7b1d3..c0c89e6685 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1011,6 +1011,9 @@  else
 +cflags += $(no-fortify-source)
 endif
 
+# Filter out LFS flags if compiler defines it by default.
++cflags += $(no-file-offset-bits-source)
+
 # Each sysdeps directory can contain header files that both will be
 # used to compile and will be installed.  Each can also contain an
 # include/ subdirectory, whose header files will be used to compile
diff --git a/configure b/configure
index 58bfb2917f..5b9cc51067 100755
--- a/configure
+++ b/configure
@@ -635,6 +635,7 @@  libc_cv_gcc_unwind_find_fde
 libc_extra_cppflags
 libc_extra_cflags
 libc_cv_cxx_thread_local
+no_file_offset_bits_source
 fortify_source
 no_fortify_source
 libc_cv_fortify_source
@@ -7784,6 +7785,37 @@  fi
 config_vars="$config_vars
 supported-fortify = $libc_cv_supported_fortify_source"
 
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+#ifndef _FILE_OFFSET_BITS
+# error _FILE_OFFSET_BITS not defined
+#endif
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"
+then :
+  libc_cv_compiler_default_file_offset_bits=yes
+else case e in #(
+  e) libc_cv_compiler_default_file_offset_bits=no ;;
+esac
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+if test "$libc_cv_compiler_default_file_offset_bits" = yes
+then :
+  no_file_offset_bits_source="-U_FILE_OFFSET_BITS"
+fi
+
+config_vars="$config_vars
+no-file-offset-bits-source = $no_file_offset_bits_source"
+
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the assembler requires one version per symbol" >&5
 printf %s "checking whether the assembler requires one version per symbol... " >&6; }
 if test ${libc_cv_symver_needs_alias+y}
diff --git a/configure.ac b/configure.ac
index 5af742ce41..160c863416 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1564,6 +1564,19 @@  AC_SUBST(no_fortify_source)
 AC_SUBST(fortify_source)
 LIBC_CONFIG_VAR([supported-fortify], [$libc_cv_supported_fortify_source])
 
+dnl Check if compiler define _FILE_OFFSET_BITS by default
+AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[]], [[
+#ifndef _FILE_OFFSET_BITS
+# error _FILE_OFFSET_BITS not defined
+#endif]])],
+	       [libc_cv_compiler_default_file_offset_bits=yes],
+	       [libc_cv_compiler_default_file_offset_bits=no])
+AS_IF([test "$libc_cv_compiler_default_file_offset_bits" = yes],
+      [no_file_offset_bits_source="-U_FILE_OFFSET_BITS"])
+AC_SUBST(no_file_offset_bits_source)
+LIBC_CONFIG_VAR([no-file-offset-bits-source], [$no_file_offset_bits_source])
+
+
 dnl Starting with binutils 2.35, GAS can attach multiple symbol versions
 dnl to one symbol (PR 23840).
 AC_CACHE_CHECK(whether the assembler requires one version per symbol,
diff --git a/conform/Makefile b/conform/Makefile
index 73a3cb6da2..50293a195b 100644
--- a/conform/Makefile
+++ b/conform/Makefile
@@ -372,7 +372,7 @@  test-xfail-UNIX98/ndbm.h/conform = yes
 test-xfail-XOPEN2K/ndbm.h/conform = yes
 test-xfail-XOPEN2K8/ndbm.h/conform = yes
 
-conformtest-cc-flags = -I../include $(+sysdep-includes) $(sysincludes) -I..
+conformtest-cc-flags =  -I../include $(+sysdep-includes) $(sysincludes) -I.. $(no-file-offset-bits-source)
 # conformtest-xfail-conds may be set by a sysdeps Makefile fragment to
 # a list of conditions that are considered to be true when encountered
 # in xfail[cond]- lines in test expectations.