maintainer-feedback requested: [Bug 275018] ports-mgmt/pkg: building with PIE and RELRO is broken when CFLAGS are set

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 10 Nov 2023 21:13:54 UTC
Bugzilla Automation <bugzilla@FreeBSD.org> has asked freebsd-pkg (Nobody)
<pkg@FreeBSD.org> for maintainer-feedback:
Bug 275018: ports-mgmt/pkg: building with PIE and RELRO is broken when CFLAGS
are set
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=275018



--- Description ---
Since WITH_PIE and WITH_RELRO were introduced to ports, it was impossible to
build ports-mgmt/pkg when CFLAGS were also set. To reproduce try to build
ports-mgmt/pkg with these settings in make.conf:

CFLAGS=-O2 -pipe -fno-strict-aliasing 
WITH_PIE=YES 
WITH_RELRO=YES

it looks like setting CFLAGS is killing -fPIC at some point which results in:

ld: error: relocation R_X86_64_32 cannot be used against local symbol;
recompile with -fPIC

I initially believed it was only a flaw, but I was encouraged to submit a PR
about it.