[FFmpeg-cvslog] configure: Enable -fno-common for Darwin targets, avoid linker warnings

Martin Storsjö git at videolan.org
Tue May 6 10:59:44 EEST 2025


ffmpeg | branch: release/7.0 | Martin Storsjö <martin at martin.st> | Tue Apr 29 10:42:48 2025 +0300| [20d711e4df4aef0d4dcc777ee035903fee764c8e] | committer: Martin Storsjö

configure: Enable -fno-common for Darwin targets, avoid linker warnings

Since GCC 10 and llvm.org Clang 11, -fno-common is the default.
However Apple's Xcode Clang hasn't followed suit yet, and still
defaults to -fcommon.

Compiling with -fcommon causes uninitialized global variables to
be treated as "common" (which allows multiple object files to have
similar definitions).

Common variables seem to have the issue that their intended alignment
isn't signaled, so the linker assumes that they may need alignment
according to their full size.

With large global tables, this can lead to linker warnings like
this, with Xcode 16.3:

    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment

This can be reproduced with a small snippet like this:

    char table[16385];
    int main(int argc, char* argv[]) { return 0; }

Compiling with -fno-common avoids this issue and warning, and
matches the default behaviour of other compilers. (Compiling with
-fno-common also avoids the risk of accidentally accepting
duplicate definitions of global variables, as long as they are
uninitialized.)

Signed-off-by: Martin Storsjö <martin at martin.st>
(cherry picked from commit f4e72eb5a3dbd25ed3ab6c9f89c42adcfc0b5e3d)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=20d711e4df4aef0d4dcc777ee035903fee764c8e
---

 configure | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/configure b/configure
index 59e06c8d57..aa29aa9eba 100755
--- a/configure
+++ b/configure
@@ -5765,6 +5765,13 @@ case $target_os in
             clang_version=$($cc -dumpversion)
             test ${clang_version%%.*} -eq 11 && add_cflags -fno-stack-check
         fi
+
+        # Xcode Clang doesn't default to -fno-common while upstream llvm.org
+        # Clang (and GCC) do. This avoids linker warnings on Xcode 16.3 about
+        # "reducing alignment of section __DATA,__common from 0x8000 to 0x4000
+        # because it exceeds segment maximum alignment".
+        check_cflags -fno-common
+
         ;;
     msys*)
         die "Native MSYS builds are discouraged, please use the MINGW environment."



More information about the ffmpeg-cvslog mailing list