Bug 294062 - lang/gcc16-devel: does not build from source on arm64
Summary: lang/gcc16-devel: does not build from source on arm64
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm64 Any
: --- Affects Many People
Assignee: Lorenzo Salvadore
URL: https://pkg-status.freebsd.org/ampere...
Keywords:
Depends on:
Blocks:
 
Reported: 2026-03-26 11:56 UTC by Luke Yasuda
Modified: 2026-08-23 18:51 UTC (History)
5 users (show)

See Also:
salvadore: maintainer-feedback+


Attachments
Restore conditional definitions (7.46 KB, patch)
2026-05-04 13:16 UTC, Lorenzo Salvadore
no flags Details | Diff
Alternate patch-libgcc_config_aarch64_cpuinfo.c with HWCAP2_CSSC and HWCAP2_MOPS (6.74 KB, patch)
2026-05-05 04:27 UTC, Mark Millard
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Yasuda 2026-03-26 11:56:56 UTC
Hi!

gcc16-devel fails to build from source on arm64:

/usr/ports/lang/gcc16-devel/work/.build/./gcc/xgcc -B/usr/ports/lang/gcc16-devel/work/.build/./gcc/ -B/usr/local/aarch64-portbld-freebsd16.0/bin/ -B/usr/local/aarch64-portbld-freebsd16.0/lib/ -isystem /usr/local/aarch64-portbld-freebsd16.0/include -isystem /usr/local/aarch64-portbld-freebsd16.0/sys-include   -fno-checking -g -O2 -pipe -D__USE_ISOC11 -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing -O2  -g -O2 -pipe  -D__USE_ISOC11 -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing  -DIN_GCC   -W -Wall -Wno-error=narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -pthread -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector  -Werror -Wno-prio-ctor-dtor -fPIC -pthread -I. -I. -I../.././gcc -I/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc -I/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/. -I/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/../gcc -I/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/../include -I/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64 -I/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS   -o cpuinfo.o -MT cpuinfo.o -MD -MP -MF cpuinfo.dep  -c /usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c -fvisibility=hidden -DHIDE_EXPORTS
/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c:51:9: error: 'AT_HWCAP' redefined [-Werror]
   51 | #define AT_HWCAP 16
      |         ^~~~~~~~
In file included from /usr/include/sys/elf32.h:32,
                 from /usr/include/machine/elf.h:38,
                 from /usr/include/sys/auxv.h:33,
                 from /usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c:35:
/usr/include/sys/elf_common.h:1018:9: note: this is the location of the previous definition
 1018 | #define AT_HWCAP        25      /* CPU feature flags. */
      |         ^~~~~~~~
/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c:53:9: error: 'AT_HWCAP3' redefined [-Werror]
   53 | #define AT_HWCAP3 29
      |         ^~~~~~~~~
/usr/include/sys/elf_common.h:1031:9: note: this is the location of the previous definition
 1031 | #define AT_HWCAP3       38      /* CPU feature flags 3. */
      |         ^~~~~~~~~
/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c:54:9: error: 'AT_HWCAP4' redefined [-Werror]
   54 | #define AT_HWCAP4 30
      |         ^~~~~~~~~
/usr/include/sys/elf_common.h:1032:9: note: this is the location of the previous definition
 1032 | #define AT_HWCAP4       39      /* CPU feature flags 4. */
      |         ^~~~~~~~~
/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c: In function '__init_cpu_features':
/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c:245:11: error: implicit declaration of function 'getauxval' [-Wimplicit-function-declaration]
  245 |   hwcap = getauxval (AT_HWCAP);
      |           ^~~~~~~~~
cc1: all warnings being treated as errors
gmake[3]: *** [/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/shared-object.mk:14: cpuinfo.o] Error 1
gmake[3]: Leaving directory '/usr/ports/lang/gcc16-devel/work/.build/aarch64-portbld-freebsd16.0/libgcc'
gmake[2]: *** [Makefile:18532: all-stage1-target-libgcc] Error 2
gmake[2]: Leaving directory '/usr/ports/lang/gcc16-devel/work/.build'
gmake[1]: *** [Makefile:25261: stage1-bubble] Error 2
gmake[1]: Leaving directory '/usr/ports/lang/gcc16-devel/work/.build'
gmake: *** [Makefile:25593: bootstrap-lean] Error 2
*** Error code 1

Stop.
make[1]: stopped making "/usr/ports/lang/gcc16-devel/work/.install_done.gcc._usr_local" in /usr/ports/lang/gcc16-devel
*** Error code 1

Stop.
make: stopped making "install clean" in /usr/ports/lang/gcc16-devel
Comment 1 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-04-01 15:27:15 UTC
Thanks for reporting!

Yes, I have also received a fair amount of emails from the package builders warning me about this issue, but unfortunately I did not find the time to study it yet. I add an example in the URL field.

I will try to debug the problem as soon as possible.
Comment 2 Mark Millard 2026-04-23 17:45:46 UTC
(In reply to Lorenzo Salvadore from comment #1)

Context: gcc16's libgcc/config/aarch64/cpuinfo.c

gcc16 is changing how the AT_HWCAP* related things are handled.

From what I read via a google search: "AT_HWCAP is a mechanism
used to detect CPU hardware capabilities (like FP, ASIMD, or
LSE atomics) at runtime for IFUNC resolvers."

It may well be that things have reverted to being linux based
in various ways.

If I gather right, from a patch draft that I saw:

No more use of: #include <asm/hwcap.h>
No more use of: #ifndef _IFUNC_ARG_HWCAP
Nor of:         #ifndef HWCAP or #ifndef HWCAP_FP or the like
Some #defines removed.
It did appear that those kept held their same values.

I have not confirmed the actual commits vs. what I read. But
this may give a clue of what direction to expect for whoever
deals with the vacations across lang/gcc* versions.
Comment 3 Mark Millard 2026-04-23 17:47:11 UTC
(In reply to Mark Millard from comment #2)

Sorry: variations, not vacations.
Comment 4 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-04-24 08:52:00 UTC
(In reply to Mark Millard from comment #2)

Thanks Mark, I was looking into the same things and I have a few more considerations:

- the issue seems to affect lang/gcc16-devel only: earlier GCC ports seem fine, so comparison with earlier GCC versions might help;
- the constants are not only defined twice, but also defined with different values (it also appears in the posted error message). I do not know which values I should keep, but I guess keeping those in /usr/include/sys/elf_common.h makes more sense. I am going to check how earlier GCC versions did it.

I will also search for the actual commit that changed the thing. Unfortunately, I have waited a lot to deal with this issue, so I have lost which was the latest snapshot that built fine. If anyone has this information, it might be helpful.
Comment 5 Mark Millard 2026-04-24 11:06:58 UTC
(In reply to Lorenzo Salvadore from comment #4)

Things like:

/wrkdirs/usr/ports/lang/gcc16-devel/work/gcc-16-20250921/libgcc/config/aarch64/cpuinfo.c:71:9: error: 'HWCAP_ASIMDDP' redefined [-Werror]
   71 | #define HWCAP_ASIMDDP           (1 << 20)
      |         ^~~~~~~~~~~~~
/usr/include/machine/elf.h:122:9: note: this is the location of the previous definition
  122 | #define HWCAP_ASIMDDP           0x00100000
      |         ^~~~~~~~~~~~~

are the same value expressed in different notations.


The:

https://portsfallout.com/fallout?page=3&port=lang/gcc16-devel&maintainer=&env=&category=&flavor=

logs go back to:

150releng-arm64-quarterly	build	2025-12-03 10:29

and that still had the problem: not far enough back. So looking in:

https://lists.freebsd.org/archives/freebsd-pkg-fallout/

appears to show the first such failing build log is in:

https://lists.freebsd.org/archives/freebsd-pkg-fallout/2025-September/801155.html

where:

From: <pkg-fallout_at_FreeBSD.org>
Date: Wed, 03 Sep 2025 04:37:28 UTC
You are receiving this mail as a port that you maintain
is failing to build on the FreeBSD package build server.
Please investigate the failure and submit a PR to fix
build.

Maintainer:     salvadore@FreeBSD.org
Log URL:        https://pkg-status.freebsd.org/ampere3/data/135arm64-default/66bfc5bccaed/logs/gcc16-devel-16.0.0.s20250817.log
Build URL:      https://pkg-status.freebsd.org/ampere3/build.html?mastername=135arm64-default&build=66bfc5bccaed
Log:

=>> Building lang/gcc16-devel
build started at Wed Sep  3 04:03:22 UTC 2025
port directory: /usr/ports/lang/gcc16-devel
package name: gcc16-devel-16.0.0.s20250817
building for: FreeBSD 135arm64-default-job-07 13.5-RELEASE-p3 FreeBSD 13.5-RELEASE-p3 arm64
maintained by: salvadore@FreeBSD.org
Makefile datestamp: -rw-r--r--  1 root  wheel  5917 Aug 28 01:03 /usr/ports/lang/gcc16-devel/Makefile
Ports top last git commit: 66bfc5bccae
Ports top unclean checkout: no
Port dir last git commit: 4e537594bf7
Port dir unclean checkout: no
Poudriere version: poudriere-git-3.4.3
Host OSVERSION: 1500052
Jail OSVERSION: 1305000
Job Id: 07
. . .
===>   gcc16-devel-16.0.0.s20250817 depends on package: gmake>=4.4.1 - not found
<snip>
/wrkdirs/usr/ports/lang/gcc16-devel/work/gcc-16-20250817/libgcc/config/aarch64/cpuinfo.c:71:9: error: 'HWCAP_ASIMDDP' redefined [-Werror]
   71 | #define HWCAP_ASIMDDP           (1 << 20)
      |         ^~~~~~~~~~~~~
/usr/include/machine/elf.h:118:9: note: this is the location of the previous definition
  118 | #define HWCAP_ASIMDDP           0x00100000
      |         ^~~~~~~~~~~~~
. . .

and so on. Looks like only the 13.5 records go back that far. Absent 13.5 having such
a long time frame, the evidence would be gone by now.

That full log is still available at:

https://pkg-status.freebsd.org/ampere3/build.html?mastername=135arm64-default&build=66bfc5bccaed

Looks like the following was the earlier successful build:

https://pkg-status.freebsd.org/ampere3/build.html?mastername=135arm64-default&build=2650762431ca

=>> Building lang/gcc16-devel
build started at Sat Aug  9 23:38:28 UTC 2025
port directory: /usr/ports/lang/gcc16-devel
package name: gcc16-devel-16.0.0.s20250727
building for: FreeBSD 135arm64-default-job-08 13.5-RELEASE-p2 FreeBSD 13.5-RELEASE-p2 arm64
maintained by: salvadore@FreeBSD.org
Makefile datestamp: -rw-r--r--  1 root  wheel  5973 Aug  5 01:11 /usr/ports/lang/gcc16-devel/Makefile
Ports top last git commit: 2650762431c
Ports top unclean checkout: no
Port dir last git commit: f03dd3069bb
Port dir unclean checkout: no
Poudriere version: poudriere-git-3.4.3
Host OSVERSION: 1500052
Jail OSVERSION: 1305000
Job Id: 08
. . .
=>> Cleaning up wrkdir
===>  Cleaning for gcc16-devel-16.0.0.s20250727
build of lang/gcc16-devel | gcc16-devel-16.0.0.s20250727 ended at Sun Aug 10 06:13:11 UTC 2025
build time: 06:34:45


That should put bounds on when the change was made upstream.
Comment 6 Mark Millard 2026-04-24 11:14:44 UTC
(In reply to Mark Millard from comment #5)

Actually, main-arm64 history also goes back that far but
does not happen to provide any better-timed information.
(For one: it completes its build attempts less often,
using a debug jail world that take longer.)
Comment 7 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-04-24 11:45:11 UTC
(In reply to Mark Millard from comment #5)

I was refering to the values in comment #0, for example

/usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c:51:9: error: 'AT_HWCAP' redefined [-Werror]
   51 | #define AT_HWCAP 16
      |         ^~~~~~~~
In file included from /usr/include/sys/elf32.h:32,
                 from /usr/include/machine/elf.h:38,
                 from /usr/include/sys/auxv.h:33,
                 from /usr/ports/lang/gcc16-devel/work/gcc-16-20260315/libgcc/config/aarch64/cpuinfo.c:35:
/usr/include/sys/elf_common.h:1018:9: note: this is the location of the previous definition
 1018 | #define AT_HWCAP        25      /* CPU feature flags. */
      |         ^~~~~~~~

Here redefinition is with different values.
Comment 8 Mark Millard 2026-04-24 15:53:00 UTC
(In reply to Lorenzo Salvadore from comment #7)

When I looked, gcc has had its libgcc/config/aarch64/cpuinfo.c
with #define AT_HWCAP 16 longterm --but in a #ifndef .

By contrast:

/usr/include/sys/elf_common.h:1018:9: note: this is the location of the previous definition
 1018 | #define AT_HWCAP        25      /* CPU feature flags. */
      |         ^~~~~~~~

is FreeBSD specific instead of using what gcc has long had for
its own definition.

The difference is the lack of #ifndef use, not any change of value
by the gcc folks.

See:

https://github.com/gcc-mirror/gcc/commit/a6bb6934a491015c4d3f08763455d86ccfb3bcbe

for when the #ifndef's were removed but the old 16 value
was left in place. (There are other more recent updates as well.)
Comment 9 Mark Millard 2026-04-24 16:05:10 UTC
Remember that the original libgcc code in that file used the
linux /usr/include/asm-arm/asm/hwcap.h as an include that
defined values that the #ifndef's avoided replacing. The
linux definitions were used if different --instead of using
the libgcc values:

#if __has_include(<asm/hwcap.h>)
#include <asm/hwcap.h>
#endif

That is no longer the case.
Comment 10 Mark Millard 2026-04-24 16:12:36 UTC
(In reply to Lorenzo Salvadore from comment #7)

FYI: here is some text from the original/creating commit
of libgcc's cpuinfo.c on 2023-Dec-15:

#ifndef AT_HWCAP
#define AT_HWCAP 16
#endif

The 16 value has never varied in that file but was allowed
to be replaced (via having the #ifndef logic).
Comment 11 Mark Millard 2026-04-24 16:43:54 UTC
(In reply to Lorenzo Salvadore from comment #7)

And I finally found the linux definition for the likes
of AT_HWCAP :

https://github.com/torvalds/linux/blob/master/include/uapi/linux/auxvec.h

has:

. . .
#define AT_HWCAP  16    /* arch dependent hints at CPU capabilities */
. . .
#define AT_HWCAP2 26	/* extension of AT_HWCAP */
. . .
#define AT_HWCAP3 29	/* extension of AT_HWCAP */
#define AT_HWCAP4 30	/* extension of AT_HWCAP */
. . .


As for what that file has for the value 25:

#define AT_RANDOM 25	/* address of 16 random bytes */


Looks to me like the usual case of gcc* uses what linux uses
but FreeBSD does not always do so.
Comment 12 Mark Millard 2026-04-24 16:49:53 UTC
(In reply to Mark Millard from comment #11)

As for FreeBSD source:

https://cgit.freebsd.org/src/tree/sys/sys/elf_common.h

has the value 16 being for:

#define	AT_CANARY	16	/* Canary for SSP. */

Looks like FreeBSD is going to have to patch lang/gcc1[6789]*
and later libgcc/config/aarch64/cpuinfo.c files, unlike before.
Comment 13 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-05-02 15:32:11 UTC
I wonder if the right solution is patching GCC (better upstream, otherwise in ports) or aligning our own definitions to what Linux and GCC do. I think that redefinition of constants to the same value would be allowed (but if I am wrong please correct me). Why do we define those constants differently?

I add in CC a few people that might be able to help deciding if we need to patch the ports or elf_common.h instead.

Additional note: lang/gcc17-devel has just been created and of course is affected by the same bug. Soon I will also create lang/gcc16, which is expected to be affected as well.
Comment 14 Konstantin Belousov freebsd_committer freebsd_triage 2026-05-02 15:35:01 UTC
(In reply to Lorenzo Salvadore from comment #13)
No, FreeBSD cannot change these values.  They form the ABI and ABI is fixed.
gcc needs to adapt to use the FreeBSD values on FreeBSD (assuming the content
provided in AT_HWCAP is compatible, at last on the source level).
Comment 15 Mark Millard 2026-05-02 17:10:50 UTC
(In reply to Lorenzo Salvadore from comment #13)

> Why do we define those constants differently?

I'd guess that that this is just the ordering of the
historical activities:

#define	AT_CANARY	16	/* Canary for SSP. */

was made part of the FreeBSD ABI before:

#define AT_HWCAP . . .

was added. By then the mismatch requirement was in
place for 16. So, as far as FreeBSD is concerned,
gcc*'s AT_HWCAP has always needed FreeBSD to adjust
it, something that was never upstreamed to have
FreeBSD OS specifics as far as I can tell.

What varies now is how to make the adjustment. The
old way no longer works as-is.
Comment 16 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-05-04 13:16:32 UTC
Created attachment 270411 [details]
Restore conditional definitions

This patch should fix the problem. Could you test it please? My testing queue is already long and I have a few issues testing arm64 on my amd64 laptop that I have not fixed yet, so help would be very welcome and would allow for a faster fix.

Assuming that it works, I will try to upstream it (i.e. ask to revert the upstream commit that introduced the issue). I will also patch lang/gcc16 similarly (I still have to create this port). If upstream accepts to revert the commit, it will not be necessary to patch lang/gcc17-devel: we can simply wait for the first weekly snapshot including the fix.
Comment 17 Mark Millard 2026-05-04 16:40:44 UTC
(In reply to Lorenzo Salvadore from comment #16)

I should be able to get to testing it. It might not be immediately,
however.

Given their justification for the changes gcc made, I doubt they
are going to want to fully revert for FreeBSD: the old way was an
overall maintenance problem for them that they are avoiding. More
than the #ifndef . . . #endif logic changed.

It may be best to point out that they now hard-code Linux ABI
values that other OS's such as FreeBSD can have some differences
and that previously they implicitly supported a way overriding
various of their (default) values and ask for a means that enables
just that much. Such could still avoid them having two sources of
truth in use, one override the other.
Comment 18 Mark Millard 2026-05-04 16:50:04 UTC
(In reply to Lorenzo Salvadore from comment #16)

To be clear, they removed what your patch file has as:

++#include <asm/hwcap.h>

That was the 2nd source of truth that they want to avoid
maintaining a relationship with in their code base.

If they can do something to avoid involving them
maintaining any such relationship with a 2nd source of
truth in their normal code base, they might be more
likely to be willing to support such a change.
Comment 19 Mark Millard 2026-05-04 17:17:59 UTC
(In reply to Mark Millard from comment #18)

I should have also said:

asm/hwcap.h is a linux header. So the change being something
that avoids looking for that file and instead uses some path
that would be expected to not already exist unless deliberately
being newly created would work for them avoiding the linux
header.

(The test for file existence should track, of course.)

May be such a change could involve a name something like:

hwcap_os_specific_abi_value_overrides.h

that would be unlikely to otherwise be created.

For FreeBSD source, that could exist and in turn #include
the normal FreeBSD source of values.

None of this avoids having to check on adjustments by gcc
to the name/value pairs (additions, removals, modifications)
over future version releases. Sometimes such may be a FreeBSD
adjustment as well.
Comment 20 Mark Millard 2026-05-04 17:42:34 UTC
(In reply to Lorenzo Salvadore from comment #16)

Another issue is: an initial submittal for the general
issue and idea to gcc probably should be ASAP. It is
very late to be adjusting gcc16 from there point of
view --or so I would expect. Specific proposal diffs
could be updated as needed.

Back when the first build failures happened would have
likely had more chance of them adopting changes. Now
I'm not so sure.

Did you check for if the differences between the old
content and the new had any additions in the new? If
the new has additions, just reverting to the old
would be insufficient.
Comment 21 Luke Yasuda 2026-05-04 18:06:35 UTC
(In reply to Lorenzo Salvadore from comment #16)
I built and installed gcc16-devel with the patch applied on arm64 on cfarm427.cfarm.net, but I didn't do any further testing.
Comment 22 Mark Millard 2026-05-04 19:10:56 UTC
(In reply to Lorenzo Salvadore from comment #16)

I have submitted:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125182

to get a start on this with the gcc folks.
Comment 23 Mark Millard 2026-05-05 00:47:01 UTC
(In reply to Lorenzo Salvadore from comment #4)

[I used outputs from "grep '#define' cpuinfo.c | sort -u"
commands on extracted gcc* source code to find the below.]

Well, I've looked and the following shows just differences
between gcc15's and gcc16-devel's cpuinfo.c for aarch64:

# diff -w -u gcc15-cpuinfo-sorted.txt gcc16-cpuinfo-sorted.txt | grep '^[-+]'
--- gcc15-cpuinfo-sorted.txt	2026-05-04 17:10:08.713529000 -0700
+++ gcc16-cpuinfo-sorted.txt	2026-05-04 17:07:19.042049000 -0700
+#define AT_HWCAP3 29
+#define AT_HWCAP4 30
+#define HWCAP2_CSSC		(1UL << 34)
-#define HWCAP2_DGH (1 << 15)
-#define HWCAP2_EBF16 (1UL << 32)
+#define HWCAP2_MOPS		(1UL << 43)
-#define HWCAP2_MTE3 (1 << 22)
-#define HWCAP2_RPRES (1 << 21)
-#define HWCAP2_SVEAES (1 << 2)
-#define HWCAP2_SVEBF16 (1 << 12)
-#define HWCAP2_SVEI8MM (1 << 9)
-#define HWCAP2_SVE_EBF16 (1UL << 33)
-#define HWCAP_AES (1 << 3)
-#define HWCAP_CPUID (1 << 11)
-#define HWCAP_EVTSTRM (1 << 2)
-#define HWCAP_PACA (1 << 30)
-#define HWCAP_PACG (1UL << 31)
-#define HWCAP_SHA1 (1 << 5)
-#define HWCAP_SHA512 (1 << 21)
+#define __IFUNC_ARG_SIZE_HWCAP2 (sizeof (unsigned long) * 3)
+#define __IFUNC_ARG_SIZE_HWCAP3 (sizeof (unsigned long) * 4)
+#define __IFUNC_ARG_SIZE_HWCAP4 (sizeof (unsigned long) * 5)

Reverting to the old content from gcc15 would be missing
AT_HWCAP3, AT_HWCAP4, HWCAP2_MOPS, __IFUNC_ARG_SIZE_HWCAP2,
__IFUNC_ARG_SIZE_HWCAP3, and __IFUNC_ARG_SIZE_HWCAP4.

(It would also have 15 extra HWCAP*_* that gcc16 does not have.)


Then, instead, grabbing the commit before the #ifndef and related
removals and doing similarly with it and the modern cpuinfo.c I
get some differences:

 # diff -w -u gcc16-cpuinfo-with-ifndef-still-sorted.txt gcc16-cpuinfo-sorted.txt | grep '^[-+]' | less
--- gcc16-cpuinfo-with-ifndef-still-sorted.txt  2026-05-04 17:40:02.909901000 -0700
+++ gcc16-cpuinfo-sorted.txt    2026-05-04 17:07:19.042049000 -0700
+#define HWCAP2_CSSC            (1UL << 34)
-#define HWCAP2_DGH (1 << 15)
-#define HWCAP2_EBF16 (1UL << 32)
+#define HWCAP2_MOPS            (1UL << 43)
-#define HWCAP2_MTE3 (1 << 22)
-#define HWCAP2_RPRES (1 << 21)
-#define HWCAP2_SVEAES (1 << 2)
-#define HWCAP2_SVEBF16 (1 << 12)
-#define HWCAP2_SVEI8MM (1 << 9)
-#define HWCAP2_SVE_EBF16 (1UL << 33)
-#define HWCAP_AES (1 << 3)
-#define HWCAP_CPUID (1 << 11)
-#define HWCAP_EVTSTRM (1 << 2)
-#define HWCAP_PACA (1 << 30)
-#define HWCAP_PACG (1UL << 31)
-#define HWCAP_SHA1 (1 << 5)
-#define HWCAP_SHA512 (1 << 21)

HWCAP2_CSSC and HWCAP2_MOPS were added after the cpuinfo.c's
code structure was changed.

I'll have to see how your Restore conditional definitions
file compares.
Comment 24 Mark Millard 2026-05-05 01:51:44 UTC
(In reply to Lorenzo Salvadore from comment #16)

The restore looks incomplete relative to lang/gcc16-devel's
cpuinfo.c file's definitions of *HWCAP* #define names.

Details . . .

Comparing your diff's ++ lines (additions) '+ ' lines
(unchanged) and +- lines (removals) to the modern
cpuinfo.c #define lines (sorted), I get and end result
that looks like:

# diff -w -u ~/gcc16-cpuinfo-revert-converted-sorted.txt gcc16-cpuinfo-sorted.txt | grep '^[-+]' | less
--- /root/gcc16-cpuinfo-revert-converted-sorted.txt     2026-05-04 18:06:24.955280000 -0700
+++ gcc16-cpuinfo-sorted.txt    2026-05-04 17:07:19.042049000 -0700
+#define HWCAP2_CSSC            (1UL << 34)
-#define HWCAP2_DGH (1 << 15)
-#define HWCAP2_EBF16 (1UL << 32)
+#define HWCAP2_MOPS            (1UL << 43)
-#define HWCAP2_MTE3 (1 << 22)
-#define HWCAP2_RPRES (1 << 21)
-#define HWCAP2_SVEAES (1 << 2)
-#define HWCAP2_SVEBF16 (1 << 12)
-#define HWCAP2_SVEI8MM (1 << 9)
-#define HWCAP2_SVE_EBF16 (1UL << 33)
-#define HWCAP_AES (1 << 3)
-#define HWCAP_CPUID (1 << 11)
-#define HWCAP_EVTSTRM (1 << 2)
-#define HWCAP_PACA (1 << 30)
-#define HWCAP_PACG (1UL << 31)
-#define HWCAP_SHA1 (1 << 5)
-#define HWCAP_SHA512 (1 << 21)
+#define extractBits(val, start, number) \
+#define getCPUFeature(id, ftr) __asm__("mrs %0, " #id : "=r"(ftr))
+#define setCPUFeature(F) feat |= 1UL << F

HWCAP2_CSSC and HWCAP2_MOPS show up as missing in your
diff. So, at least, they would not get #ifndef . . . #endif
context via use of your diff. But I'm not sure that
presuming matching values for FreeBSD is appropriate.
FreeBSD would seem to need to declare its ABI values,
even if those deliberately match Linux and such happen
to still be available (not checked).

There are also the AT_HWCAP3, AT_HWCAP4 that FreeBSD
has values for. As stands, FreeBSD does not have
__IFUNC_ARG_SIZE_HWCAP* names of its own. They might
not really be FreeBSD ABI values specific based on the
type of content (descriptive instead of just unique
numbering?) and, so, okay as cpuinfo.c has them already?

(There are also the 3 #defines, starting with extractBits,
that are after your range of making adjustments the *HWCAP*
names. So those are probably fine as being left alone.)
of replacements. I only analyzed #define lines.)

Overall: more update is needed to span lang/gcc16-devel's
libgcc cpuinfo.c #define content as far as I can tell.

(Note: The above above and other explorations were a
process of discovery. I do not have prior knowledge to
validate my activity with.)
Comment 25 Mark Millard 2026-05-05 04:27:20 UTC
Created attachment 270422 [details]
Alternate patch-libgcc_config_aarch64_cpuinfo.c with HWCAP2_CSSC and HWCAP2_MOPS

This does not address FreeBSD having its own HWCAP2_CSSC and
HWCAP2_MOPS definitions if such are needed. It just provides
the libgcc defaults (with #ifndef . . . #endif use).

Nor have I checked AT_HWCAP3 and AT_HWCAP4 vs. FreeBSD details
yet. (They are new since lang/gcc15 .) There could be other
related names to deal with, depending on just what needs a
independent FreeBSD ABI #define (even if it agrees with
the Linux for such).

Nor does this deal with having the gcc folks be able to avoid
the linux asm/hwcap.h header that they were trying to avoid
having as a 2nd source of truth for their code base.

I have not yet tested any sort of building, much less testing
of operation if it does build.
Comment 26 Mark Millard 2026-05-05 17:05:42 UTC
(In reply to Mark Millard from comment #25)

/usr/src/sys/arm64/include/elf.h in main does have both:

/usr/src/sys/arm64/include/elf.h:#define        HWCAP2_CSSC             (1UL << 34)
and:
/usr/src/sys/arm64/include/elf.h:#define        HWCAP2_MOPS             (1UL << 43)

The 2 above match gcc defaults.

FreeeBSD has _IFUNC_ARG_HWCAP in:

/usr/src/sys/arm64/include/ifunc.h:#define _IFUNC_ARG_HWCAP (1ULL << 62)

It happens to match gcc defaults. But to use the FreeBSD
definition of _IFUNC_ARG_HWCAP would require the use of:

/usr/src/sys/arm64/include/ifunc.h
not just:
/usr/src/sys/sys/elf_common.h

I've not (yet?) tracked down if /usr/src/sys/arm64/include/ifunc.h
is used instead of depending on the gcc1ยง default for
_IFUNC_ARG_HWCAP . It may not be a potentially varying ABI specific
value so might be okay as is.

/usr/src/sys/sys/elf_common.h in main has:

#define   AT_HWCAP4       39      /* CPU feature flags 4. */

which does not match the gcc16/linux value 30. No other names
contain HWCAP4 in in FreeBSD source code ( ignoring
compat/linux ). Just gcc16+(?) has __IFUNC_ARG_SIZE_HWCAP4 .

gcc16's conf/aarch64  does not seem to have any HWCAP32_* examples
but FreeBSD source code does.

/usr/src/sys/sys/elf_common.h in main has:

#define	AT_HWCAP3	38	/* CPU feature flags 3. */

which does not match the gcc16/linux value 29. FreeBSD has
the names:

/usr/src/sys/arm64/include/elf.h:#define	HWCAP3_MTE_FAR		(1 << 0)
/usr/src/sys/arm64/include/elf.h:#define	HWCAP3_MTE_STORE_ONLY	(1 << 1)
/usr/src/sys/arm64/include/elf.h:#define	HWCAP3_LSFE		(1 << 2)
/usr/src/sys/arm64/include/elf.h:#define	HWCAP3_LS64		(1 << 3)

gcc16 does not have any HWCAP3_* names.

gcc16 has the names __IFUNC_ARG_SIZE_HWCAP[234] but FreeBSD
source does not.


So AT_HWCAP, AT_HWCAP3, and AT_HWCAP4 need the distinct FreeBSD ABI
values. AT_HWCAP2 should likely get the FreeBSD source definition
as well. This looks to be handled.

Less clear is if the FreeBSD source code's _IFUNC_ARG_HWCAP should
be in use, given what it is and the lack of a distinct value.
Similarly is: if FreeBSD should have __IFUNC_ARG_SIZE_HWCAP[234]
and then should be using them despite probable lack of a distinct
values.


The rest seems to span what gcc16 has for such #defines --and also
agree with gcc16.
Comment 27 Mark Millard 2026-05-05 22:55:47 UTC
(In reply to Lorenzo Salvadore from comment #16)

Based on using my alternate patch that also has
HWCAP2_CSSC and HWCAP2_MOPS defines with
#ifndef . . . #endif usage, an example aarch64
bulk build of lang/gcc16-devel completed:

poudriere bulk -jmain-CA76 -palt lang/gcc16-devel
. . .
[02:24:31] [01] [02:05:01] Finished   lang/gcc16-devel | gcc16-devel-16.1.1.s20260502: Success

For reference:

# poudriere ports -l
PORTSTREE METHOD TIMESTAMP           PATH
alt       null   2025-04-06 14:15:11 /usr/ports-alt
default   null   2021-04-18 02:05:47 /usr/ports

# ~/fbsd-based-on-what-commit.sh -C /usr/ports-alt/
9cdc1baa6392 (HEAD -> main, freebsd/main, freebsd/HEAD) */*: Fix misplaced BROKEN line
Author:     Max Brazhnikov <makc@FreeBSD.org>
Commit:     Max Brazhnikov <makc@FreeBSD.org>
CommitDate: 2026-05-05 19:40:49 +0000
branch: main
merge-base: 9cdc1baa6392b40f31cb87fac60c60246d612871
merge-base: CommitDate: 2026-05-05 19:40:49 +0000
n745294 (--first-parent --count for merge-base)

# git -C /usr/ports-alt/ status
On branch main
Your branch is up to date with 'freebsd/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	lang/gcc16-devel/files/patch-libgcc_config_aarch64_cpuinfo.c

nothing added to commit but untracked files present (use "git add" to track)


I also did an amd64 bulk build:

poudriere bulk -jmain-ZNV4 -palt lang/gcc16-devel
. . .
[00:26:17] [01] [00:21:51] Finished   lang/gcc16-devel | gcc16-devel-16.1.1.s20260502: Success
Comment 28 Mark Millard 2026-05-11 17:27:02 UTC
(In reply to Lorenzo Salvadore from comment #13)

Turns out that libgcc/config/aarch64/lse-init.c contains
__gnu_linux__ only code for __getauxval and more:

#include "auto-target.h"

/* Define the symbol gating the LSE implementations.  */
_Bool __aarch64_have_lse_atomics
  __attribute__((visibility("hidden"), nocommon));

/* Gate availability of __getauxval on glibc.  All AArch64-supporting glibc
   versions support it.  */
#ifdef __gnu_linux__

# define AT_HWCAP	16
# define HWCAP_ATOMICS	(1 << 8)

unsigned long int __getauxval (unsigned long int);

/* Use a higher priority to ensure it runs before user constructors
   and library constructors with priority 100. */
static void __attribute__((constructor (90)))
init_have_lse_atomics (void)
{
  unsigned long hwcap = __getauxval (AT_HWCAP);
  __aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0;
}

#endif /* __gnu_linux__  */

So it looks like this area has its own issues as well: no code
for non-linux OS's, such as the FreeBSD OS.


And I'm being questioned on things I've  not looked into as
an independent set of eyes for just the build failure, not
being a lang/gcc* or devel/freebsd-gcc maintainer or
developer -- or for devel/llvm* or system clang/clang++ .

QUOTE
. . .

Should there be a #elif that includes a different header for FreeBSD? Does it support the ABI for ifuncs?

How is the similar issue resolved for libgcc/config/aarch64/lse-init.c?
END QUOTE

You and/or other maintainers/developers of lang/gcc* and
devel/freebsd-gcc* probably need to get involved in:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125182
Comment 29 Mark Millard 2026-05-12 19:19:17 UTC
FYI:

John Baldwin ( jhb@FreeBSD.org ) is now involved at:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125182

including for other things that came up beyond the
original report of the AT_HWCAP* ABI values issue.
Comment 30 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-06-11 15:56:37 UTC
(In reply to Mark Millard from comment #23)

Thanks for spotting the two constants I have missed and sorry that I had such a long pause working on this issue. I am finally back.

With the next lang/gcc16-devel and lang/gcc17-devel snapshots I am going to merge the patch and we shall finally fix these two ports. Assuming everything works as expected, then it will be the turn of lang/gcc16.

Of course, this will fix the ports in the ports tree, but more work will be needed to fix upstream too.
Comment 31 commit-hook freebsd_committer freebsd_triage 2026-06-15 19:00:05 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=6931d2c01673c154dcc5459cafb5058f73740f63

commit 6931d2c01673c154dcc5459cafb5058f73740f63
Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
AuthorDate: 2026-05-09 14:36:12 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2026-06-15 18:57:48 +0000

    lang/gcc17-devel: Fix build on arm64

    GCC upstream has removed conditional definitions for some constants,
    defining them directly with the same values used on Linux. However,
    FreeBSD values for the same constants are different. Then revert
    upstream commit.

    Co-authored-by: Mark Millard <marklmi26-fbsd@yahoo.com>
    PR:             294062
    Reported by:    Luke Yasuda <jing@jing.rocks>

 lang/gcc17-devel/files/patch-libcxxrt              |   4 +-
 .../patch-libgcc_config_aarch64_cpuinfo.c (new)    | 273 +++++++++++++++++++++
 2 files changed, 275 insertions(+), 2 deletions(-)
Comment 32 commit-hook freebsd_committer freebsd_triage 2026-06-15 19:01:08 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=8195f251248c3cb0f05ca35dc80d802cf4ea2fc5

commit 8195f251248c3cb0f05ca35dc80d802cf4ea2fc5
Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
AuthorDate: 2026-05-04 13:04:16 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2026-06-15 18:57:46 +0000

    lang/gcc16-devel: Fix build on arm64

    GCC upstream has removed conditional definitions for some constants,
    defining them directly with the same values used on Linux. However,
    FreeBSD values for the same constants are different. Then revert
    upstream commit.

    Co-authored-by: Mark Millard <marklmi26-fbsd@yahoo.com>
    PR:             294062
    Reported by:    Luke Yasuda <jing@jing.rocks>

 lang/gcc16-devel/files/patch-libcxxrt              |   4 +-
 .../patch-libgcc_config_aarch64_cpuinfo.c (new)    | 279 +++++++++++++++++++++
 2 files changed, 281 insertions(+), 2 deletions(-)
Comment 33 commit-hook freebsd_committer freebsd_triage 2026-07-12 10:46:19 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=13e3a42d6eebb30b822e95a16ba09ce14bcb557d

commit 13e3a42d6eebb30b822e95a16ba09ce14bcb557d
Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
AuthorDate: 2026-07-12 10:43:23 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2026-07-12 10:44:44 +0000

    lang/gcc16: Fix build on arm64

    GCC upstream has removed conditional definitions for some constants,
    defining them directly with the same values used on Linux. However,
    FreeBSD values for the same constants are different. Then revert
    upstream commit.

    Co-authored-by: Mark Millard <marklmi26-fbsd@yahoo.com>
    PR:             294062
    Reported by:    Luke Yasuda <jing@jing.rocks>

 .../patch-libgcc_config_aarch64_cpuinfo.c (new)    | 279 +++++++++++++++++++++
 1 file changed, 279 insertions(+)
Comment 34 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-07-12 10:49:13 UTC
With this last commit all affected ports should now build successfully again.
Thanks to everyone who helped!
Comment 35 Mark Millard 2026-07-12 19:59:01 UTC
(In reply to Lorenzo Salvadore from comment #34)

An oddity is that the likes of:

https://lists.freebsd.org/archives/freebsd-pkg-fallout/2026-July/966801.html
("[package - 144arm64-default][lang/gcc16] Failed for gcc16-16.1.0_2 in build")

does not show up in what:

https://portsfallout.com/fallout?port=lang%2Fgcc&maintainer=&env=&category=&flavor=

lists. No aarch64 lang/gcc16 (no -devel) shows up for any
FreeBSD version/variation --despite the :

https://lists.freebsd.org/archives/freebsd-pkg-fallout/2026-*/

having examples of such fallout.
Comment 36 Mark Millard 2026-07-12 20:10:32 UTC
(In reply to commit-hook from comment #33)

It would seem that 2026Q3 should probably get the lang/gcc16 update
as well, instead of waiting for 2026Q4. (At least once main has a
successful build based on the update.)
Comment 37 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-07-22 15:39:36 UTC
(In reply to Mark Millard from comment #36)

Of course you are right. For now only FreeBSD 15 has a package according to Freshports ( https://www.freshports.org/lang/gcc16 ). Once the packages are built for 14 and 16 as well, I shall fix the quarterly branch.
Comment 38 Robert Clausecker freebsd_committer freebsd_triage 2026-08-18 08:29:51 UTC
Please MFH these changes (all build fixes in fact) as the quarterly branch too is affected.
Comment 39 commit-hook freebsd_committer freebsd_triage 2026-08-23 18:47:43 UTC
A commit in branch 2026Q3 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=a4894e75909f4f2fad03a067cc669332818a23cb

commit a4894e75909f4f2fad03a067cc669332818a23cb
Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
AuthorDate: 2026-07-12 10:43:23 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2026-08-23 18:44:34 +0000

    lang/gcc16: Fix build on arm64

    GCC upstream has removed conditional definitions for some constants,
    defining them directly with the same values used on Linux. However,
    FreeBSD values for the same constants are different. Then revert
    upstream commit.

    Co-authored-by: Mark Millard <marklmi26-fbsd@yahoo.com>
    PR:             294062
    Reported by:    Luke Yasuda <jing@jing.rocks>

    (cherry picked from commit 13e3a42d6eebb30b822e95a16ba09ce14bcb557d)

 .../patch-libgcc_config_aarch64_cpuinfo.c (new)    | 279 +++++++++++++++++++++
 1 file changed, 279 insertions(+)
Comment 40 Lorenzo Salvadore freebsd_committer freebsd_triage 2026-08-23 18:51:04 UTC
The fix for lang/gcc16 has finally been merged into the quarterly branch (sorry it took a long time). The fix for the other ports had been done just before the 2026Q3 quarterly branch was created so they have been already fixed there too.

We should finally be able to close this bug report.