{"thread":{"id":"65703","subject":"[PATCH] pkt-line: initialize packet_buffer to avoid macOS linker warning","startedAt":"2026-05-27T17:12:02Z","lastAt":"2026-06-02T07:38:00Z","messageCount":8,"participants":["Harald Nordgren via GitGitGadget","Junio C Hamano","Harald Nordgren"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"544178","messageId":"pull.2313.git.git.1779901919956.gitgitgadget@gmail.com","threadId":"65703","inReplyTo":null,"subject":"[PATCH] pkt-line: initialize packet_buffer to avoid macOS linker warning","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-05-27T17:11:59Z","receivedAt":"2026-05-27T17:12:02Z","isPatch":true,"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n    pkt-line: initialize packet_buffer to avoid macOS linker warning\n    \n    Removes this warning:\n    \n    $ make -s -j8\n    GIT_VERSION=2.54.0.380.gc69baaf57b\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n    \n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2313%2FHaraldNordgren%2Fpkt-line-init-buffer-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v1\nPull-Request: https://github.com/git/git/pull/2313\n\n pkt-line.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/pkt-line.c b/pkt-line.c\nindex 3fc3e9ea70..cfd2799677 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -8,7 +8,7 @@\n #include \"trace.h\"\n #include \"write-or-die.h\"\n \n-char packet_buffer[LARGE_PACKET_MAX];\n+char packet_buffer[LARGE_PACKET_MAX] = {0};\n static const char *packet_trace_prefix = \"git\";\n static struct trace_key trace_packet = TRACE_KEY_INIT(PACKET);\n static struct trace_key trace_pack = TRACE_KEY_INIT(PACKFILE);\n\nbase-commit: c69baaf57ba26cf117c2b6793802877f19738b0d\n-- \ngitgitgadget\n"},{"id":"544206","messageId":"xmqqse7cjku5.fsf@gitster.g","threadId":"65703","inReplyTo":"pull.2313.git.git.1779901919956.gitgitgadget@gmail.com","subject":"Re: [PATCH] pkt-line: initialize packet_buffer to avoid macOS linker warning","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-05-28T03:04:34Z","receivedAt":"2026-05-28T03:04:37Z","isPatch":true,"body":"\"Harald Nordgren via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Harald Nordgren <haraldnordgren@gmail.com>\n>\n> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n> ---\n>     pkt-line: initialize packet_buffer to avoid macOS linker warning\n>     \n>     Removes this warning:\n>     \n>     $ make -s -j8\n>     GIT_VERSION=2.54.0.380.gc69baaf57b\n>     ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment\n\nThis sounds nuts.\n\nNot complaining at you, but we are talking about char[]; what\nalignment constraints are they talking about?\n\n> diff --git a/pkt-line.c b/pkt-line.c\n> index 3fc3e9ea70..cfd2799677 100644\n> --- a/pkt-line.c\n> +++ b/pkt-line.c\n> @@ -8,7 +8,7 @@\n>  #include \"trace.h\"\n>  #include \"write-or-die.h\"\n>  \n> -char packet_buffer[LARGE_PACKET_MAX];\n> +char packet_buffer[LARGE_PACKET_MAX] = {0};\n\nI do not like this; it sounds more like a workaround for broken\nlinker (and compiler to certain degree).\n\nThis, compiled with a stupid compiler that is too faithful to the\nsource text, may make the resulting object file on disk larger by\n64kB, since the original said \"I need 64kB area in BSS with its\nstarting address recorded as 'packet_buffer'\" (which costs almost\nnothing) and the updated says \"Here is a 64kB of literal data\"\n(which would record the literal data, even if its bytes happen to be\nall NUL).  Luckily both versions of GCC and Clang I have notices\nthat the literal data is all NUL and still keeps the area in BSS\nwith no change in the object file size or output from \"size\npacket-line.o\", so to me and others on similar systems as I use,\nthis probably is a benign no-op, but not everywhere.\n\nAre there different versions of C compiler available on macOS for\nyou to try?  I am hoping that even though vendor compilers tend to\nlag a bit behind from the public upstream, the problems may have\nalready been fixed in more fresher versions.\n\n    ... goes and looks ...\n\nAccording to Internet, Xcode 16.3 or newer introduced this insanity,\nit seems.  How about adding -fno-common to your CFLAGS?  If it\nsolves the issue, then we can think about teaching config.mak.uname\nto detect macOS with problematic versions of compilers and add the\nflag as workaround.\n\n\n>  static const char *packet_trace_prefix = \"git\";\n>  static struct trace_key trace_packet = TRACE_KEY_INIT(PACKET);\n>  static struct trace_key trace_pack = TRACE_KEY_INIT(PACKFILE);\n>\n> base-commit: c69baaf57ba26cf117c2b6793802877f19738b0d\n"},{"id":"544220","messageId":"CAHwyqnWjHTpWfbMcBHOabny5NQN7xTZmxew2yDWWu3AoosngWA@mail.gmail.com","threadId":"65703","inReplyTo":"xmqqse7cjku5.fsf@gitster.g","subject":"Re: [PATCH] pkt-line: initialize packet_buffer to avoid macOS linker warning","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-05-28T07:40:37Z","receivedAt":"2026-05-28T07:41:15Z","isPatch":true,"body":"> According to Internet, Xcode 16.3 or newer introduced this insanity,\n> it seems.  How about adding -fno-common to your CFLAGS?  If it\n> solves the issue, then we can think about teaching config.mak.uname\n> to detect macOS with problematic versions of compilers and add the\n> flag as workaround.\n\nYes, this works:\n\n```\nmake -s CFLAGS_APPEND=\"-fno-common\"\n```\n\n\nHarald\n"},{"id":"544221","messageId":"CAHwyqnXgxnDNiq0UWyAsz6CHvroYPZ36EGbaUn=-OmP6w3gsWw@mail.gmail.com","threadId":"65703","inReplyTo":"CAHwyqnWjHTpWfbMcBHOabny5NQN7xTZmxew2yDWWu3AoosngWA@mail.gmail.com","subject":"Re: [PATCH] pkt-line: initialize packet_buffer to avoid macOS linker warning","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-05-28T08:14:15Z","receivedAt":"2026-05-28T08:14:56Z","isPatch":true,"body":"So maybe we can do something like this then?\n\n```\n+       # Silence Xcode 16.3+ linker warning about __DATA,__common alignment.\n+       LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n\n's/.*PROJECT:ld-\\([0-9]*\\).*/\\1/p')\n+        ifeq ($(shell test \"$(LD_MAJOR_VERSION)\" -ge 1167 && echo 1),1)\n+               BASIC_CFLAGS += -fno-common\n+        endif\n```\n\nHarald\n\nOn Thu, May 28, 2026 at 9:40 AM Harald Nordgren\n<haraldnordgren@gmail.com> wrote:\n>\n> > According to Internet, Xcode 16.3 or newer introduced this insanity,\n> > it seems.  How about adding -fno-common to your CFLAGS?  If it\n> > solves the issue, then we can think about teaching config.mak.uname\n> > to detect macOS with problematic versions of compilers and add the\n> > flag as workaround.\n>\n> Yes, this works:\n>\n> ```\n> make -s CFLAGS_APPEND=\"-fno-common\"\n> ```\n>\n>\n> Harald\n"},{"id":"544235","messageId":"xmqqjysnjnt4.fsf@gitster.g","threadId":"65703","inReplyTo":"CAHwyqnXgxnDNiq0UWyAsz6CHvroYPZ36EGbaUn=-OmP6w3gsWw@mail.gmail.com","subject":"Re: [PATCH] pkt-line: initialize packet_buffer to avoid macOS linker warning","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-05-28T20:12:39Z","receivedAt":"2026-05-28T20:12:42Z","isPatch":true,"body":"Harald Nordgren <haraldnordgren@gmail.com> writes:\n\n> So maybe we can do something like this then?\n>\n> ```\n> +       # Silence Xcode 16.3+ linker warning about __DATA,__common alignment.\n> +       LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n\n> 's/.*PROJECT:ld-\\([0-9]*\\).*/\\1/p')\n> +        ifeq ($(shell test \"$(LD_MAJOR_VERSION)\" -ge 1167 && echo 1),1)\n> +               BASIC_CFLAGS += -fno-common\n> +        endif\n> ```\n>\n> Harald\n\nI do not exactly know where these magic numbers and patterns for\n\"ld\" comes from, but yes, something like that in macOS specific\nsection would be what I had in mind.\n\nThanks.\n"},{"id":"544269","messageId":"pull.2313.v2.git.git.1780065163866.gitgitgadget@gmail.com","threadId":"65703","inReplyTo":"pull.2313.git.git.1779901919956.gitgitgadget@gmail.com","subject":"[PATCH v2] config.mak.uname: avoid macOS linker warning on Xcode 16.3+","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-05-29T14:32:43Z","receivedAt":"2026-05-29T14:32:45Z","isPatch":true,"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nBuilding on macOS with Xcode 16.3 or newer emits:\n\n    ld: warning: reducing alignment of section __DATA,__common\n    from 0x8000 to 0x4000 because it exceeds segment maximum\n    alignment\n\nPass -fno-common when \"ld -v\" reports ld-1167 or newer, so tentative\ndefinitions of large arrays go into BSS instead of __DATA,__common.\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n    pkt-line: initialize packet_buffer to avoid macOS linker warning\n    \n     * Check MacOS ld version instead\n       (https://en.wikipedia.org/wiki/Xcode#Xcode_15.0_-_16.x_(since_visionOS_support)_2)\n    \n    Parsing output of\n    \n    ❯ ld -v\n    @(#)PROGRAM:ld PROJECT:ld-1267\n    BUILD 18:30:29 Apr 22 2026\n    configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em armv8m.main armv8.1m.main\n    will use ld-classic for: armv6 armv7 armv7s i386 armv6m armv7k armv7m armv7em\n    LTO support using: LLVM version 21.0.0 (static support for 30, runtime is 30)\n    TAPI support using: Apple TAPI version 21.0.0 (tapi-2100.0.2.6)\n    \n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2313%2FHaraldNordgren%2Fpkt-line-init-buffer-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v2\nPull-Request: https://github.com/git/git/pull/2313\n\nRange-diff vs v1:\n\n 1:  1c1c66d85b < -:  ---------- pkt-line: initialize packet_buffer to avoid macOS linker warning\n -:  ---------- > 1:  0e660a346e config.mak.uname: avoid macOS linker warning on Xcode 16.3+\n\n\n config.mak.uname | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/config.mak.uname b/config.mak.uname\nindex ce5e7de779..d4d55cb324 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -163,6 +163,12 @@ ifeq ($(uname_S),Darwin)\n \t\tNEEDS_GOOD_LIBICONV = UnfortunatelyYes\n         endif\n \n+\t# Silence Xcode 16.3+ linker warning about __DATA,__common alignment.\n+\tLD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:ld-\\([0-9]*\\).*/\\1/p')\n+        ifeq ($(shell test \"$(LD_MAJOR_VERSION)\" -ge 1167 && echo 1),1)\n+\t\tBASIC_CFLAGS += -fno-common\n+        endif\n+\n \t# The builtin FSMonitor on MacOS builds upon Simple-IPC.  Both require\n \t# Unix domain sockets and PThreads.\n         ifndef NO_PTHREADS\n\nbase-commit: c69baaf57ba26cf117c2b6793802877f19738b0d\n-- \ngitgitgadget\n"},{"id":"544440","messageId":"xmqqzf1d2894.fsf@gitster.g","threadId":"65703","inReplyTo":"pull.2313.v2.git.git.1780065163866.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] config.mak.uname: avoid macOS linker warning on Xcode 16.3+","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-06-01T22:41:59Z","receivedAt":"2026-06-01T22:42:02Z","isPatch":true,"body":"\"Harald Nordgren via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> diff --git a/config.mak.uname b/config.mak.uname\n> index ce5e7de779..d4d55cb324 100644\n> --- a/config.mak.uname\n> +++ b/config.mak.uname\n> @@ -163,6 +163,12 @@ ifeq ($(uname_S),Darwin)\n>  \t\tNEEDS_GOOD_LIBICONV = UnfortunatelyYes\n>          endif\n>  \n> +\t# Silence Xcode 16.3+ linker warning about __DATA,__common alignment.\n> +\tLD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:ld-\\([0-9]*\\).*/\\1/p')\n\nIf LD_MAJOR_VERSION ever ends up being an empty string, then ...\n\n> +        ifeq ($(shell test \"$(LD_MAJOR_VERSION)\" -ge 1167 && echo 1),1)\n\n... this \"test\" would see\n\n\ttest \"\" -ge 1167\n\nthat would result in errors like\n\n\t/bin/bash: line 1: test: : integer expected\n\tdash: 1: test: Illegal number: \n\nWhile this won't break the build (the `ifeq` will just evaluate to\nfalse), it can be noisy.\n\nPerhaps\n\n\ttest -n \"$(LD_MAJOR_VERSION)\" &&\n\nin front?  We know from your \"sed\" invocation that we won't see\nanything other than an empty string that is not a number, so I do\nnot think we have to worry about feeding a non-number to the\ncomparison against 1167 except for the \"ah, no match, empty string\"\ncase.\n\nOther than that, looking good.  Thanks.\n\n> +\t\tBASIC_CFLAGS += -fno-common\n> +        endif\n> +\n>  \t# The builtin FSMonitor on MacOS builds upon Simple-IPC.  Both require\n>  \t# Unix domain sockets and PThreads.\n>          ifndef NO_PTHREADS\n>\n> base-commit: c69baaf57ba26cf117c2b6793802877f19738b0d\n"},{"id":"544462","messageId":"pull.2313.v3.git.git.1780385878555.gitgitgadget@gmail.com","threadId":"65703","inReplyTo":"pull.2313.v2.git.git.1780065163866.gitgitgadget@gmail.com","subject":"[PATCH v3] config.mak.uname: avoid macOS linker warning on Xcode 16.3+","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-06-02T07:37:58Z","receivedAt":"2026-06-02T07:38:00Z","isPatch":true,"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nBuilding on macOS with Xcode 16.3 or newer emits:\n\n    ld: warning: reducing alignment of section __DATA,__common\n    from 0x8000 to 0x4000 because it exceeds segment maximum\n    alignment\n\nPass -fno-common when \"ld -v\" reports ld-1167 or newer, so tentative\ndefinitions of large arrays go into BSS instead of __DATA,__common.\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n    fix macOS linker warning\n    \n    Check for empty LD_MAJOR_VERSION.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2313%2FHaraldNordgren%2Fpkt-line-init-buffer-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v3\nPull-Request: https://github.com/git/git/pull/2313\n\nRange-diff vs v2:\n\n 1:  0e660a346e ! 1:  f864912c53 config.mak.uname: avoid macOS linker warning on Xcode 16.3+\n     @@ config.mak.uname: ifeq ($(uname_S),Darwin)\n       \n      +\t# Silence Xcode 16.3+ linker warning about __DATA,__common alignment.\n      +\tLD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:ld-\\([0-9]*\\).*/\\1/p')\n     -+        ifeq ($(shell test \"$(LD_MAJOR_VERSION)\" -ge 1167 && echo 1),1)\n     ++        ifeq ($(shell test -n \"$(LD_MAJOR_VERSION)\" && test \"$(LD_MAJOR_VERSION)\" -ge 1167 && echo 1),1)\n      +\t\tBASIC_CFLAGS += -fno-common\n      +        endif\n      +\n\n\n config.mak.uname | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/config.mak.uname b/config.mak.uname\nindex f9a5ad9720..8719e09f66 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -173,6 +173,12 @@ ifeq ($(uname_S),Darwin)\n \t\tNEEDS_GOOD_LIBICONV = UnfortunatelyYes\n         endif\n \n+\t# Silence Xcode 16.3+ linker warning about __DATA,__common alignment.\n+\tLD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:ld-\\([0-9]*\\).*/\\1/p')\n+        ifeq ($(shell test -n \"$(LD_MAJOR_VERSION)\" && test \"$(LD_MAJOR_VERSION)\" -ge 1167 && echo 1),1)\n+\t\tBASIC_CFLAGS += -fno-common\n+        endif\n+\n \t# The builtin FSMonitor on MacOS builds upon Simple-IPC.  Both require\n \t# Unix domain sockets and PThreads.\n         ifndef NO_PTHREADS\n\nbase-commit: 1666c1265231b0bc5f613fbbf3f0a9896cdef76e\n-- \ngitgitgadget\n"}]}