[Bug 253275] [exp-run] base system PIE default

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Fri Feb 19 15:05:07 UTC 2021


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=253275

--- Comment #16 from Ed Maste <emaste at freebsd.org> ---
(In reply to Dawid Gorecki from comment #14)
> Some ports build static libraries and it seems that currently the best way to
> fix this is by setting WITHOUT_PIE.

Yes. This affects two classes of ports:

1. those that build their own static libraries using the base system Mk
infrastructure, such as devel/libphk

Example error:

ld: error: can't create dynamic relocation R_X86_64_32 against local symbol in
readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to
allow text relocations in the output
>>> defined in ../../libphk.a(phk_argv.o)
>>> referenced by phk_argv.c
>>>               phk_argv.o:(PhkArgvParse) in archive ../../libphk.a

A patch for this one is now open in D28790 https://reviews.freebsd.org/D28790

2. those that link against static libraries provided by the base system, such
as net/freevrrpd

ld: error: can't create dynamic relocation R_X86_64_32 against local symbol in
readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to
allow text relocations in the output
>>> defined in /usr/lib/libnetgraph.a(sock.o)
>>> referenced by sock.c:78 (/poudriere/data/src-PR253275/lib/libnetgraph/sock.c:78)
>>>               sock.o:(NgMkSockNode) in archive /usr/lib/libnetgraph.a

For this one, PIE disabled in the port's Makefile in r566067.

> Another reason that I've seen is caused by setting CFLAGS="${CFLAGS}" in
> MAKE_ARGS. I'm not really sure how bmake works in this case, but I think that
> it starts ignoring any further processing of CFLAGS and we are left with
> CFLAGS from sys.mk and no modifications made in bsd.prog.mk are taken into
> account. This happens for www/mathopd. I removed MAKE_ARGS for that and it
> built fine. -DFREEBSD_SENDFILE was also properly passed further. I haven't
> tested if it works after building though, but I don't see any reason why it
> shouldn't.

Right - port Makefiles are processed w/o using bsd.opts.mk, and so in that
context CFLAGS does not contain -fPIE. Then the submake for the software itself
is invoked as make CLFAGS=<whatever> ... (as a result of MAKE_ARGS) and that
overrides bsd.prog.mk's attempt to add -fPIE.

I tried building www/mathopd with and without MAKE_ARGS set, and without it
there are a number of additional CFLAGS set, in addition to -fPIE:

-MD  -MF.depend.base64.o -MTbase64.o -std=gnu99 -Wno-format-zero-length
-nobuiltininc -idirafter /usr/lib/clang/11.0.1/include -fstack-protector-strong
   -Qunused-arguments

so it would definitely need testing.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the freebsd-ports-bugs mailing list