git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] pkt-line: initialize packet_buffer to avoid macOS linker warning

From
Junio C Hamano <gitster@pobox.com>
Date
May 28, 2026, 03:04 UTC
Message-ID
<xmqqse7cjku5.fsf@gitster.g>
In-Reply-To
<pull.2313.git.git.1779901919956.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>     pkt-line: initialize packet_buffer to avoid macOS linker warning
>     
>     Removes this warning:
>     
>     $ make -s -j8
>     GIT_VERSION=2.54.0.380.gc69baaf57b
>     ld: warning: reducing alignment of section __DATA,__common from 0x8000 to 0x4000 because it exceeds segment maximum alignment
This sounds nuts.

Not complaining at you, but we are talking about char[]; what alignment constraints are they talking about?

Show 10 quoted lines
> diff --git a/pkt-line.c b/pkt-line.c
> index 3fc3e9ea70..cfd2799677 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -8,7 +8,7 @@
>  #include "trace.h"
>  #include "write-or-die.h"
>  
> -char packet_buffer[LARGE_PACKET_MAX];
> +char packet_buffer[LARGE_PACKET_MAX] = {0};

I do not like this; it sounds more like a workaround for broken linker (and compiler to certain degree).

This, compiled with a stupid compiler that is too faithful to the source text, may make the resulting object file on disk larger by 64kB, since the original said "I need 64kB area in BSS with its starting address recorded as 'packet_buffer'" (which costs almost nothing) and the updated says "Here is a 64kB of literal data" (which would record the literal data, even if its bytes happen to be all NUL). Luckily both versions of GCC and Clang I have notices that the literal data is all NUL and still keeps the area in BSS with no change in the object file size or output from "size packet-line.o", so to me and others on similar systems as I use, this probably is a benign no-op, but not everywhere.

Are there different versions of C compiler available on macOS for you to try? I am hoping that even though vendor compilers tend to lag a bit behind from the public upstream, the problems may have already been fixed in more fresher versions.

    ... goes and looks ...

According to Internet, Xcode 16.3 or newer introduced this insanity, it seems. How about adding -fno-common to your CFLAGS? If it solves the issue, then we can think about teaching config.mak.uname to detect macOS with problematic versions of compilers and add the flag as workaround.

Show 5 quoted lines
>  static const char *packet_trace_prefix = "git";
>  static struct trace_key trace_packet = TRACE_KEY_INIT(PACKET);
>  static struct trace_key trace_pack = TRACE_KEY_INIT(PACKFILE);
>
> base-commit: c69baaf57ba26cf117c2b6793802877f19738b0d
Previous: Harald Nordgren via GitGitGadgetNext: Harald Nordgren
Message 2 of 8 in “pkt-line: initialize packet_buffer to avoid macOS linker warning”
  1. pkt-line: initialize packet_buffer to avoid macOS linker warningHarald Nordgren via GitGitGadget, May 27, 2026
  2. Junio C HamanoMay 28, 2026
  3. Harald NordgrenMay 28, 2026
  4. Harald NordgrenMay 28, 2026
  5. Junio C HamanoMay 28, 2026
  6. config.mak.uname: avoid macOS linker warning on Xcode 16.3+Harald Nordgren via GitGitGadget, May 29, 2026
  7. Junio C HamanoJun 1, 2026
  8. config.mak.uname: avoid macOS linker warning on Xcode 16.3+Harald Nordgren via GitGitGadget, Jun 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.