History

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.)

Martin Storsjö committed 1 year ago

Commit f4e72eb1 parent a0349d61 file · +7 −0Browse files

Unified · Split

configure+7−0
@@ -5851,6 +5851,13 @@ case $target_os in · 5850 unmodified lines
5851 clang_version=$($cc -dumpversion)5851 clang_version=$($cc -dumpversion)
5852 test ${clang_version%%.*} -eq 11 && add_cflags -fno-stack-check5852 test ${clang_version%%.*} -eq 11 && add_cflags -fno-stack-check
5853 fi5853 fi
5854
5855 # Xcode Clang doesn't default to -fno-common while upstream llvm.org
5856 # Clang (and GCC) do. This avoids linker warnings on Xcode 16.3 about
5857 # "reducing alignment of section __DATA,__common from 0x8000 to 0x4000
5858 # because it exceeds segment maximum alignment".
5859 check_cflags -fno-common
5860
5854 ;;5861 ;;
5855 msys*)5862 msys*)
5856 die "Native MSYS builds are discouraged, please use the MINGW environment."5863 die "Native MSYS builds are discouraged, please use the MINGW environment."

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t