Skip to content

fix macOS linker warning#2313

Open
HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:pkt-line-init-buffer
Open

fix macOS linker warning#2313
HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:pkt-line-init-buffer

Conversation

@HaraldNordgren
Copy link
Copy Markdown
Contributor

@HaraldNordgren HaraldNordgren commented May 27, 2026

Check for empty LD_MAJOR_VERSION.

@gitgitgadget-git
Copy link
Copy Markdown

There is an issue in commit 7620928:
pkt-line: initialize packet_buffer to avoid macOS linker warning

  • Commit not signed off

@HaraldNordgren HaraldNordgren force-pushed the pkt-line-init-buffer branch from 7620928 to 1c1c66d Compare May 27, 2026 16:00
@HaraldNordgren
Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.2313.git.git.1779901919956.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v1

To fetch this version to local tag pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v1

@gitgitgadget-git
Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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?

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


>  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

@gitgitgadget-git
Copy link
Copy Markdown

Harald Nordgren wrote on the Git mailing list (how to reply to this email):

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

Yes, this works:

```
make -s CFLAGS_APPEND="-fno-common"
```


Harald

@gitgitgadget-git
Copy link
Copy Markdown

Harald Nordgren wrote on the Git mailing list (how to reply to this email):

So maybe we can do something like this then?

```
+       # Silence Xcode 16.3+ linker warning about __DATA,__common alignment.
+       LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n
's/.*PROJECT:ld-\([0-9]*\).*/\1/p')
+        ifeq ($(shell test "$(LD_MAJOR_VERSION)" -ge 1167 && echo 1),1)
+               BASIC_CFLAGS += -fno-common
+        endif
```

Harald

On Thu, May 28, 2026 at 9:40 AM Harald Nordgren
<haraldnordgren@gmail.com> wrote:
>
> > 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.
>
> Yes, this works:
>
> ```
> make -s CFLAGS_APPEND="-fno-common"
> ```
>
>
> Harald

@gitgitgadget-git
Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

Harald Nordgren <haraldnordgren@gmail.com> writes:

> So maybe we can do something like this then?
>
> ```
> +       # Silence Xcode 16.3+ linker warning about __DATA,__common alignment.
> +       LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n
> 's/.*PROJECT:ld-\([0-9]*\).*/\1/p')
> +        ifeq ($(shell test "$(LD_MAJOR_VERSION)" -ge 1167 && echo 1),1)
> +               BASIC_CFLAGS += -fno-common
> +        endif
> ```
>
> Harald

I do not exactly know where these magic numbers and patterns for
"ld" comes from, but yes, something like that in macOS specific
section would be what I had in mind.

Thanks.

@HaraldNordgren HaraldNordgren force-pushed the pkt-line-init-buffer branch from 1c1c66d to 0e660a3 Compare May 29, 2026 14:30
@HaraldNordgren
Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.2313.v2.git.git.1780065163866.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v2

To fetch this version to local tag pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v2

@gitgitgadget-git
Copy link
Copy Markdown

This branch is now known as hn/macos-linker-warning.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into seen via d297f66.

@HaraldNordgren HaraldNordgren changed the title pkt-line: initialize packet_buffer to avoid macOS linker warning fix macOS linker warning May 31, 2026
@gitgitgadget-git
Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> diff --git a/config.mak.uname b/config.mak.uname
> index ce5e7de779..d4d55cb324 100644
> --- a/config.mak.uname
> +++ b/config.mak.uname
> @@ -163,6 +163,12 @@ ifeq ($(uname_S),Darwin)
>  		NEEDS_GOOD_LIBICONV = UnfortunatelyYes
>          endif
>  
> +	# Silence Xcode 16.3+ linker warning about __DATA,__common alignment.
> +	LD_MAJOR_VERSION = $(shell ld -v 2>&1 | sed -n 's/.*PROJECT:ld-\([0-9]*\).*/\1/p')

If LD_MAJOR_VERSION ever ends up being an empty string, then ...

> +        ifeq ($(shell test "$(LD_MAJOR_VERSION)" -ge 1167 && echo 1),1)

... this "test" would see

	test "" -ge 1167

that would result in errors like

	/bin/bash: line 1: test: : integer expected
	dash: 1: test: Illegal number: 

While this won't break the build (the `ifeq` will just evaluate to
false), it can be noisy.

Perhaps

	test -n "$(LD_MAJOR_VERSION)" &&

in front?  We know from your "sed" invocation that we won't see
anything other than an empty string that is not a number, so I do
not think we have to worry about feeding a non-number to the
comparison against 1167 except for the "ah, no match, empty string"
case.

Other than that, looking good.  Thanks.

> +		BASIC_CFLAGS += -fno-common
> +        endif
> +
>  	# The builtin FSMonitor on MacOS builds upon Simple-IPC.  Both require
>  	# Unix domain sockets and PThreads.
>          ifndef NO_PTHREADS
>
> base-commit: c69baaf57ba26cf117c2b6793802877f19738b0d

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into seen via 79e127e.

Building on macOS with Xcode 16.3 or newer emits:

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

Pass -fno-common when "ld -v" reports ld-1167 or newer, so tentative
definitions of large arrays go into BSS instead of __DATA,__common.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
@HaraldNordgren HaraldNordgren force-pushed the pkt-line-init-buffer branch from 0e660a3 to f864912 Compare June 2, 2026 07:34
@HaraldNordgren
Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.2313.v3.git.git.1780385878555.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v3

To fetch this version to local tag pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v3:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2313/HaraldNordgren/pkt-line-init-buffer-v3

@gitgitgadget-git
Copy link
Copy Markdown

There was a status update in the "New Topics" section about the branch hn/macos-linker-warning on the Git mailing list:

A linker warning on macOS when building with Xcode 16.3 or newer has
been avoided by passing -fno-common to the compiler when a
sufficiently new linker is detected.

Will merge to 'next'.
source: <pull.2313.v3.git.git.1780385878555.gitgitgadget@gmail.com>

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into seen via dc421db.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into seen via 2c75f64.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into next via db2ca16.

@gitgitgadget-git gitgitgadget-git Bot added the next label Jun 4, 2026
@gitgitgadget-git
Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/macos-linker-warning on the Git mailing list:

A linker warning on macOS when building with Xcode 16.3 or newer has
been avoided by passing -fno-common to the compiler when a
sufficiently new linker is detected.

Will merge to 'master'.
source: <pull.2313.v3.git.git.1780385878555.gitgitgadget@gmail.com>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant