Bug 274429 - ports-mgmt/portconfig: not WITH_PIE safe
Summary: ports-mgmt/portconfig: 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 Some People
Assignee: Baptiste Daroussin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-12 11:58 UTC by Alexander Leidinger
Modified: 2023-10-12 20:48 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (bapt)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Leidinger freebsd_committer freebsd_triage 2023-10-12 11:58:40 UTC
Hi,

the Makefile needs PIE_UNSAFE=yes (or a real fix to the build).

Bye,
Alexander.
Comment 1 Mina Galić freebsd_triage 2023-10-12 12:11:45 UTC
maybe create the bug upstream, too: https://gitlab.com/alfix/portconfig/-/issues/
what does the failure look like?
Comment 2 Alexander Leidinger freebsd_committer freebsd_triage 2023-10-12 12:30:33 UTC
(In reply to Mina Galić from comment #1)
Ticket created upstream.

The issue is, that it can not relocate some symbols of a static library when linking.


===== env: NO_DEPENDS=yes USER=root UID=0 GID=0
===>  Building for portconfig-0.5
--- portconfig.o ---
cc -O2 -pipe -O2 -pipe -mtune=native -fvectorize -march=native  -fstack-protector-strong -fPIE -fPIC -isystem /usr/local/include -fno-strict-aliasing  -O2 -pipe -mtune=native -fvec
torize -I/usr/local/include -std=gnu99 -Wall -Wextra -c portconfig.c -o portconfig.o
--- portconfig ---
cc  -fstack-protector-strong -pie -Wl,-zrelro -Wl,-znow -L/usr/local/lib  -L/usr/local/lib -Wl,-Bstatic -v -Wl,-whole-archive -lbsddialog  -Wl,-no-whole-archive -L/usr/lib -lncurse
sw -ltinfow  -Wl,-Bdynamic -Wl,--export-dynamic portconfig.o -o portconfig
FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)
Target: x86_64-unknown-freebsd15.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/ld" -pie --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o portconfig /usr/lib/Scrt1.o /usr/lib/crti.o /usr/lib/crtbeginS.o -L/
usr/local/lib -L/usr/local/lib -L/usr/lib -L/usr/lib -zrelro -znow -Bstatic -whole-archive -lbsddialog -no-whole-archive -lncursesw -ltinfow -Bdynamic --export-dynamic portconfig.o
 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtendS.o /usr/lib/crtn.o
ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in /usr/lib/libtinfow.a(visbuf.o)
>>> referenced by visbuf.c:0 (/space/system/usr_src/contrib/ncurses/ncurses/trace/visbuf.c:0)
>>>               visbuf.o:(_nc_visbuf2n) in archive /usr/lib/libtinfow.a

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in /usr/lib/libtinfow.a(visbuf.o)
>>> referenced by visbuf.c:0 (/space/system/usr_src/contrib/ncurses/ncurses/trace/visbuf.c:0)
>>>               visbuf.o:(_nc_visbuf2n) in archive /usr/lib/libtinfow.a
Comment 3 Alfonso S. Siciliano freebsd_committer freebsd_triage 2023-10-12 12:35:59 UTC
Mina we can continue the discussion also here. it makes no difference to me then I' ll update/fix in upstream.

Alexander thank you for the report. I did not know this new feature, I am reading CHANGES right now (PIE, RELRO, BIND_NOW). You wrote several comments (bug #268982 , bug #268901 , etc), does exist a central resource to help to migrate/use the feature?

I am currently trying to reproduce the failure.
Comment 4 Alexander Leidinger freebsd_committer freebsd_triage 2023-10-12 13:24:17 UTC
(In reply to Alfonso S. Siciliano from comment #3)
I'm not aware of a central effort to make all ports buildable with PIE/RELRO/BIND_NOW. Portmgr may know more about that.

I build all the ports with those options, and out of the over 1000 ports which are build only 13 are failing.
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-10-12 14:15:08 UTC
A commit in branch main references this bug:

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

commit 076804781f89ca075b2358cf459c24c817321482
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2023-10-12 14:09:52 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2023-10-12 14:14:52 +0000

    ports-mgmt/portconfig: allow to build with PIE

    portsconfig is a dynamic binary which static link to all the
    dependencies, which causes a problem when it links with base provided
    static libraries as they are not PIE friendly.

    PR:             274429
    Reported by:    netchild

 ports-mgmt/portconfig/files/patch-Makefile (new) | 13 +++++++++++++
 1 file changed, 13 insertions(+)