Bug 282797 - lang/gcc15-devel: stage2 fails to compile enable-execute-stack.c
Summary: lang/gcc15-devel: stage2 fails to compile enable-execute-stack.c
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Lorenzo Salvadore
URL: https://pkg-status.freebsd.org/ampere...
Keywords:
Depends on:
Blocks:
 
Reported: 2024-11-16 13:56 UTC by John F. Carr
Modified: 2025-06-05 13:55 UTC (History)
1 user (show)

See Also:
salvadore: maintainer-feedback+


Attachments
avoid compiler error in libgcc (563 bytes, patch)
2024-11-17 17:03 UTC, John F. Carr
no flags Details | Diff
files/patch-libgcc_unwind-dw2-fde-dip.c for avoiding ElfW redefinition (507 bytes, patch)
2025-02-28 08:06 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 John F. Carr 2024-11-16 13:56:43 UTC
On aarch64, FreeBSD 14.2-PRERELEASE, lang/gcc15-devel fails when built with poudriere:

enable-execute-stack.c:33:13: error: 'check_enabling' declared 'static' but never defined [-Werror=unused-function]
   33 | static void check_enabling (void) __attribute__ ((unused));
      |             ^~~~~~~~~~~~~~

The error comes from /wrkdirs/usr/ports/lang/gcc15-devel/work/.build/./gcc/xgcc.

The file with the error is named enable-execute-stack-mprotect.c in the source and has not changed in the past decade.  There is also a file named enable-execute-stack-empty.c.  Possibly gcc is stricter than it used to be.  Possibly FreeBSD started using the mprotect flavor instead of the empty flavor.
Comment 1 Lorenzo Salvadore freebsd_committer freebsd_triage 2024-11-17 13:40:03 UTC
Bug reproduced on CURRENT too:
https://pkg-status.freebsd.org/ampere2/data/main-arm64-default/pdfee61567d9e_s36887e04947/logs/gcc15-devel-15.0.0.s20241110.log

I will look into it as soon as possible. However, as usual, there are many GCC issues open and it might need a bit of time.
Patches are welcome.
Comment 2 John F. Carr 2024-11-17 17:03:13 UTC
Created attachment 255240 [details]
avoid compiler error in libgcc
Comment 3 commit-hook freebsd_committer freebsd_triage 2024-11-28 10:34:50 UTC
A commit in branch main references this bug:

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

commit 2c87bf1deb36339194333ca8720483c0c8aa0ec4
Author:     John F. Carr <jfc@mit.edu>
AuthorDate: 2024-11-23 12:41:34 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2024-11-28 10:32:29 +0000

    lang/gcc15-devel: Fix stage2 fail on aarch64

    PR:             282797

 .../patch-libgcc_enable-execute-stack-mprotect.c (new)    | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Comment 4 Lorenzo Salvadore freebsd_committer freebsd_triage 2024-11-28 10:40:58 UTC
Please confirm that the issue is fixed. I had only little time so I have been a bit sloppier than usual on testing (it is a -devel port, so it should not be a big deal)...
Comment 5 John F. Carr 2024-11-28 17:24:38 UTC
With the fix for the execute-stack bug I get a different error later:

/wrkdirs/usr/ports/lang/gcc15-devel/work/gcc-15-20241124/libgcc/unwind-dw2-fde-dip.c:69:10: error: 'ElfW' redefined [-Werror]
   69 | # define ElfW __ElfN
      |          ^~~~
In file included from /usr/include/machine/elf.h:45,
                 from /usr/include/elf.h:37,
                 from /wrkdirs/usr/ports/lang/gcc15-devel/work/gcc-15-20241124/libgcc/unwind-dw2-fde-dip.c:36:
/usr/include/sys/elf_generic.h:59:9: note: this is the location of the previous definition
   59 | #define ElfW(x)         __ElfN(x)
      |         ^~~~
Comment 6 Mark Millard 2025-02-28 08:06:45 UTC
Created attachment 258055 [details]
files/patch-libgcc_unwind-dw2-fde-dip.c for avoiding ElfW redefinition

The  files/patch-libgcc_unwind-dw2-fde-dip.c was
only compile tested --and only for:

) a lang/gcc15-devel poudriere(-devel) based build on aarch64
) a lang/gcc15-devel poudriere(-devel) based build on amd64


For reference (aarch64 context example):

# uname -apKU
FreeBSD aarch64-main-pbase 15.0-CURRENT FreeBSD 15.0-CURRENT #2 main-n275290-9ef38a01aea8-dirty: Tue Feb 18 19:42:12 PST 2025     root@aarch64-main-pbase:/usr/obj/BUILDs/main-CA76-nodbg-clang/usr/main-src/arm64.aarch64/sys/GENERIC-NODBG-CA76 arm64 aarch64 1500031 1500031

# ~/fbsd-based-on-what-commit.sh -C /usr/ports/
9f2922f28a6f (HEAD -> main, freebsd/main, freebsd/HEAD) devel/aws-crt-cpp: Update to 0.30.2
Author:     Nuno Teixeira <eduardo@FreeBSD.org>
Commit:     Nuno Teixeira <eduardo@FreeBSD.org>
CommitDate: 2025-02-12 21:03:47 +0000
branch: main
merge-base: 9f2922f28a6f65e1fcac7c1d9fba79a93c898a01
merge-base: CommitDate: 2025-02-12 21:03:47 +0000
n695802 (--first-parent --count for merge-base)
Comment 7 Mark Millard 2025-02-28 08:29:04 UTC
(In reply to Mark Millard from comment #6)

Note: "only compile tested" should also have mentioned:

    and only on main [so: 15 as stands]
Comment 8 Mark Millard 2025-05-19 07:16:35 UTC
Comment on attachment 258055 [details]
files/patch-libgcc_unwind-dw2-fde-dip.c for avoiding ElfW redefinition

Lorenzo S. plans on a different patch that has
a similar end result: lack of the ElfW
definition. My patch also changed things for
__DragonFly__ but I never had a clue if that
was appropriate. It just made very clear what
I was suggesting to avoid.
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-05-22 15:29:51 UTC
A commit in branch main references this bug:

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

commit 5926446a4973a707e4ba3c8af737029d6f13f176
Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
AuthorDate: 2025-05-22 15:08:28 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2025-05-22 15:27:55 +0000

    lang/gcc16-devel: Unbreak on aarch64

    FreeBSD defines ElfW(x) to translate Linux's convention to FreeBSD's convention.
    GCC defines ElfW to convert its convention to FreeBSD's convention. This patch
    removes the conversion defined by GCC so that the FreeBSD conversion only is
    applied.

    Co-authored-by: Mark Millard <marklmi26-fbsd@yahoo.com>

    PR:             282797
    Reported by:    John F. Carr <jfc@mit.edu>
    Email Thread:   https://lists.freebsd.org/archives/freebsd-toolchain/2025-May/002282.html

 lang/gcc16-devel/Makefile                          |  1 +
 .../files/patch-libgcc_unwind-dw2-fde-dip.c (new)  | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)
Comment 10 commit-hook freebsd_committer freebsd_triage 2025-05-22 15:29:52 UTC
A commit in branch main references this bug:

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

commit 1a30d52dd1d6174e42c42dbbc4bed624c7c122cb
Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
AuthorDate: 2025-05-16 16:12:36 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2025-05-22 15:27:54 +0000

    lang/gcc15-devel: Unbreak on aarch64

    FreeBSD defines ElfW(x) to translate Linux's convention to FreeBSD's convention.
    GCC defines ElfW to convert its convention to FreeBSD's convention. This patch
    removes the conversion defined by GCC so that the FreeBSD conversion only is
    applied.

    Co-authored-by: Mark Millard <marklmi26-fbsd@yahoo.com>

    PR:             282797
    Reported by:    John F. Carr <jfc@mit.edu>
    Email Thread:   https://lists.freebsd.org/archives/freebsd-toolchain/2025-May/002282.html

 lang/gcc15-devel/Makefile                          |  1 +
 .../files/patch-libgcc_unwind-dw2-fde-dip.c (new)  | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)
Comment 11 Lorenzo Salvadore freebsd_committer freebsd_triage 2025-05-22 15:33:13 UTC
The fix has been committed on lang/gcc15-devel and lang/gcc16-devel for now. Assuming everything works fine, I will patch lang/gcc15 too.

Finally, if everything works fine in our ports tree, I will file a bug report upstream with our successfully tested patch.
Comment 12 Mark Millard 2025-05-22 18:19:17 UTC
(In reply to Lorenzo Salvadore from comment #11)

I will note that there is another  known issue for
main-arm64 and main-armv7 that prevents lang/gcc1[45]*
from building. (I've not tested a lang/gcc16* but such
likely has the same issue.) The issue is tied to
main's adding libsys and needing to resolve what are
hidden symbols historically.

In the poudriere build logs the issue shows up as:

checking for library containing strerror... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
gmake[2]: *** [Makefile:11359: configure-stage2-libiberty] Error 1

The message is somewhat of a misnomer for the details
of what is going on: GCC_NO_EXECUTABLES was set because
of an unexpected link failure so later tests fail just
based on being after GCC_NO_EXECUTABLES.

The config.log gives a better idea of the actual
problem.

So expect to use 14.* and 13.* contexts that do not
have a libsys to see such builds complete.
Comment 13 Mark Millard 2025-05-22 18:26:37 UTC
(In reply to Mark Millard from comment #12)

An example of specific type of error for lang/gcc[145]*
is:

/usr/local/bin/ld: conftest: hidden symbol `__aeabi_unwind_cpp_pr0' in /wrkdirs/usr/ports/lang/gcc14/work/.build/./prev-gcc/libgcc_eh.a(unwind-arm.o) is referenced by DSO
Comment 14 Mark Millard 2025-05-23 13:29:06 UTC
(In reply to Mark Millard from comment #12)

I only should have listed main-armv7, not main-arm64
for the hidden symbol `__aeabi_unwind_cpp_pr0' problem.
Comment 15 commit-hook freebsd_committer freebsd_triage 2025-06-05 13:55:20 UTC
A commit in branch main references this bug:

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

commit 7ea3d17abb65b5be5e7cfb4df864aeb17208d241
Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
AuthorDate: 2025-05-28 09:41:11 +0000
Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
CommitDate: 2025-06-05 13:54:07 +0000

    lang/gcc15: Unbreak on aarch64

    FreeBSD defines ElfW(x) to translate Linux's convention to FreeBSD's convention.
    GCC defines ElfW to convert its convention to FreeBSD's convention. This patch
    removes the conversion defined by GCC so that the FreeBSD conversion only is
    applied.

    Co-authored-by: Mark Millard <marklmi26-fbsd@yahoo.com>

    PR:             282797
    Reported by:    John F. Carr <jfc@mit.edu>
    Email Thread:   https://lists.freebsd.org/archives/freebsd-toolchain/2025-May/002282.html lang/gcc15:

 lang/gcc15/Makefile                                |  1 +
 .../files/patch-libgcc_unwind-dw2-fde-dip.c (new)  | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)