Bug 275039 - dns/void-zones-tools: not WITH_PIE safe
Summary: dns/void-zones-tools: not WITH_PIE safe
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Robert Clausecker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-12 12:12 UTC by Marek Zarychta
Modified: 2023-11-24 06:20 UTC (History)
2 users (show)

See Also:
vidar: maintainer-feedback+


Attachments
Fix build with WITH_PIE=YES (1.72 KB, patch)
2023-11-13 21:28 UTC, Vidar Karlsen
vidar: maintainer-approval+
Details | Diff
Updated patch (2.00 KB, patch)
2023-11-19 15:13 UTC, Vidar Karlsen
vidar: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Zarychta 2023-11-12 12:12:44 UTC
Unfortunately, the port dns/void-zones-tools is not ready for the global setting
WITH_PIE=YES 

cc binutils.o store.o hosts2zones.o  -fstack-protector-strong -pie -Wl,-zrelro  -o hosts2zones
ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
Comment 1 Vidar Karlsen 2023-11-13 21:28:50 UTC
Created attachment 246279 [details]
Fix build with WITH_PIE=YES

Thank you for bringing this issue to my attention.
Can you test the attached patch and check if it fixes the problem?
I have tested it locally and it builds and seems to work both with and without WITH_PIE.
Comment 2 Marek Zarychta 2023-11-14 20:15:57 UTC
(In reply to Vidar Karlsen from comment #1)
Yes, the solution is right, but I couldn't apply your patch, so I changed only the appropriate line in Makefile and it worked. Thanks for the fix.
Comment 3 Robert Clausecker freebsd_committer freebsd_triage 2023-11-18 07:06:05 UTC
This patch doesn't look right as it now unconditionally adds -fpic, even if we create a position-dependent binary.

I don't get why you had -fno-pic in there in the first place.  If you just remove that flag, I suspect it'll just work as expected.

Failing that, please change the port so -fpic is only passed if WITH_PIE is set.  E.g. you can do 

    CFLAGS+= ${WITH_PIE:D-fpic}

in the port Makefile.
Comment 4 Vidar Karlsen 2023-11-19 15:12:08 UTC
(In reply to Robert Clausecker from comment #3)

> This patch doesn't look right as it now unconditionally adds -fpic, even if we create a position-dependent binary.

That is a very good point.

> I don't get why you had -fno-pic in there in the first place.  If you just remove that flag, I suspect it'll just work as expected.

I don't know either. It's coming from upstream, and I don't know enough about compilers and their flags to put forth any meaningful argument about it.

Removing -fno-pic almost works, but the upstream Makefile does:
CFLAGS = $(CDEFS)
overwriting anything coming from the ports framework.
Changing that to += does seem to do the trick.
I'll upload a new patch.
Comment 5 Vidar Karlsen 2023-11-19 15:13:42 UTC
Created attachment 246424 [details]
Updated patch

Does this one work as intended?
Comment 6 Robert Clausecker freebsd_committer freebsd_triage 2023-11-19 23:11:41 UTC
Patch looks reasonable.  @Marek, does it solve your issue?
Comment 7 Marek Zarychta 2023-11-20 06:56:47 UTC
The updated patch works fine for me. Thank you!
Comment 8 Robert Clausecker freebsd_committer freebsd_triage 2023-11-20 07:03:38 UTC
Great, will commit next weekend until there's an objection from the maintainer.
Comment 9 commit-hook freebsd_committer freebsd_triage 2023-11-24 06:16:23 UTC
A commit in branch main references this bug:

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

commit 11a7b638a6c63425070e60ddcad9ebb27fad88c9
Author:     Vidar Karlsen <vidar@karlsen.tech>
AuthorDate: 2023-11-13 21:21:58 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-11-24 06:12:30 +0000

    dns/void-zones-tools: Fix build with WITH_PIE=YES

    Patch CFLAGS from being overridden and remove -fno-pic to facilitate
    building with WITH_PIE=yes

    PR:             275039
    Reported by:    Marek Zarychta

 dns/void-zones-tools/Makefile             |  1 +
 dns/void-zones-tools/files/patch-Makefile | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2023-11-24 06:18:34 UTC
A commit in branch 2023Q4 references this bug:

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

commit 690ea2e84f43fa7f8c055557c6f00238c7e4c2a8
Author:     Vidar Karlsen <vidar@karlsen.tech>
AuthorDate: 2023-11-13 21:21:58 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-11-24 06:16:16 +0000

    dns/void-zones-tools: Fix build with WITH_PIE=YES

    Patch CFLAGS from being overridden and remove -fno-pic to facilitate
    building with WITH_PIE=yes

    PR:             275039
    Reported by:    Marek Zarychta

    (cherry picked from commit 11a7b638a6c63425070e60ddcad9ebb27fad88c9)

 dns/void-zones-tools/Makefile             |  1 +
 dns/void-zones-tools/files/patch-Makefile | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
Comment 11 Robert Clausecker freebsd_committer freebsd_triage 2023-11-24 06:20:07 UTC
Thank you for your contribution.