Hi, building the port with WITH_PIE makes it fail (error message tells that ld can't relocate a specific symbol and that it should be recompiled wiht -fPIE). Until this is fixed, the port should get PIE_UNSAFE=yes in the Makefile (this fixes the build for me). Bye, Alexander.
Why are you building a kernel module with a userland-only build setting? Kernel modules are not executables, so PIE doesn't make sense for any kernel module. Maybe Mk/users/kmod.mk should be patched to set PIE_UNSAFE just as it currently sets SSP_UNSAFE? That would avoid needing to patch all the various kmod ports.
I'm not building it that way on purpose, the ports collection / poudriere is doing that automatically when the documented way of enabling WITH_PIE (and WITH_BIND_NOW and WITH_RELO) is used. I didn't check how the port builds the kld and simply used the documented workaround for ports which fail. I agree that a more generic fix is favourable.
I added a PIE_UNSAFE tag locally in kmod.mk. The only downside I see is that if a port installs both kernel modules and userland binaries that the userland binaries are also automatically tagged as PIE_UNSAFE.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=1e765fa4cbf289770f6c1a55b4ec339c2fc44990 commit 1e765fa4cbf289770f6c1a55b4ec339c2fc44990 Author: Rene Ladan <rene@FreeBSD.org> AuthorDate: 2023-01-20 12:22:41 +0000 Commit: Rene Ladan <rene@FreeBSD.org> CommitDate: 2023-01-21 13:13:46 +0000 Mk/Uses: tag kmod.mk as PIE_UNSAFE Kernel modules are not executables, so marking them safe for being a position-indepentent executable does not make sense. PR: 268922 Mk/Uses/kmod.mk | 1 + 1 file changed, 1 insertion(+)
A commit in branch 2023Q1 references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=833eef7f4c845d48d28749a14e45d0eb4b960a74 commit 833eef7f4c845d48d28749a14e45d0eb4b960a74 Author: Rene Ladan <rene@FreeBSD.org> AuthorDate: 2023-01-20 12:22:41 +0000 Commit: Rene Ladan <rene@FreeBSD.org> CommitDate: 2023-01-21 13:35:27 +0000 Mk/Uses: tag kmod.mk as PIE_UNSAFE Kernel modules are not executables, so marking them safe for being a position-indepentent executable does not make sense. PR: 268922 (cherry picked from commit 1e765fa4cbf289770f6c1a55b4ec339c2fc44990) Mk/Uses/kmod.mk | 1 + 1 file changed, 1 insertion(+)