pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Adding link flags for the static version

Open netchild opened this issue 1 year ago • 1 comments

Hi,

when I use LDFLAGS=XXX those flags are only applied to the dynamic linking, the pkg-static build doesn't see them.

Example with -fsanitize=cfi (dynamic build has all the options, static build hasn't):

--- pkg ---
cc -o pkg add.o alias.o annotate.o audit.o autoremove.o check.o clean.o config.o create.o delete.o event.o fetch.o globals.o info.o install.o key.o lock.o main.o plugins.o query.o register.o repo.o rquery.o search.o set.o shell.o shlib.o ssh.o stats.o triggers.o update.o updating.o upgrade.o utils.o version.o which.o  -Wl,-znow -fsanitize=cfi -fvisibility=hidden -fsanitize-cfi-cross-dso -flto=thin -fno-sanitize-trap=all -fsanitize-recover=all -pie -Wl,-zrelro -fstack-protector-strong  -Wl,-Bstatic  -Wl,-whole-archive -L/wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg -lpkg_flat -Wl,-no-whole-archive    -Wl,-Bdynamic -lelf -ljail -lssl -lcrypto -larchive -lbz2 -lz -llzma -lprivatezstd -lm -pthread -lutil -lmd  -Wl,--export-dynamic
--- pkg-static ---
cc -o pkg-static add.o alias.o annotate.o audit.o autoremove.o check.o clean.o config.o create.o delete.o event.o fetch.o globals.o info.o install.o key.o lock.o main.o plugins.o query.o register.o repo.o rquery.o search.o set.o shell.o shlib.o ssh.o stats.o triggers.o update.o updating.o upgrade.o utils.o version.o which.o -static -L/wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg -lpkg_flat  -lelf -ljail -lssl -lcrypto -larchive -lbz2 -lz -llzma -lprivatezstd -lm -pthread -lutil -lmd
--- pkg ---
ld: error: undefined symbol: __cfi_slowpath_diag
>>> referenced by event.c
>>>               pkg.lto.event.o:(cleanup_handler.52c52c1eb832dce3a09137c36f3b0e8a.cfi)
>>> referenced by ucl_emitter_utils.c
>>>               /wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg/pkg.lto.libpkg_flat.a(ucl_emitter_utils.o at 3229650).o:(ucl_elt_string_write_json.cfi)
>>> referenced by ucl_emitter_utils.c
>>>               /wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg/pkg.lto.libpkg_flat.a(ucl_emitter_utils.o at 3229650).o:(ucl_elt_string_write_json.cfi)
>>> referenced 3030 more times
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** [pkg] Error code 1

Bye, Alexander.

netchild avatar May 21 '24 12:05 netchild

On Tue 21 May 05:00, Alexander Leidinger wrote:

Hi,

when I use LDFLAGS=XXX those flags are only applied to the dynamic linking, the pkg-static build doesn't see them.

Example with -fsanitize=cfi (dynamic build has all the options, static build hasn't):

--- pkg ---
cc -o pkg add.o alias.o annotate.o audit.o autoremove.o check.o clean.o config.o create.o delete.o event.o fetch.o globals.o info.o install.o key.o lock.o main.o plugins.o query.o register.o repo.o rquery.o search.o set.o shell.o shlib.o ssh.o stats.o triggers.o update.o updating.o upgrade.o utils.o version.o which.o  -Wl,-znow -fsanitize=cfi -fvisibility=hidden -fsanitize-cfi-cross-dso -flto=thin -fno-sanitize-trap=all -fsanitize-recover=all -pie -Wl,-zrelro -fstack-protector-strong  -Wl,-Bstatic  -Wl,-whole-archive -L/wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg -lpkg_flat -Wl,-no-whole-archive    -Wl,-Bdynamic -lelf -ljail -lssl -lcrypto -larchive -lbz2 -lz -llzma -lprivatezstd -lm -pthread -lutil -lmd  -Wl,--export-dynamic
--- pkg-static ---
cc -o pkg-static add.o alias.o annotate.o audit.o autoremove.o check.o clean.o config.o create.o delete.o event.o fetch.o globals.o info.o install.o key.o lock.o main.o plugins.o query.o register.o repo.o rquery.o search.o set.o shell.o shlib.o ssh.o stats.o triggers.o update.o updating.o upgrade.o utils.o version.o which.o -static -L/wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg -lpkg_flat  -lelf -ljail -lssl -lcrypto -larchive -lbz2 -lz -llzma -lprivatezstd -lm -pthread -lutil -lmd
--- pkg ---
ld: error: undefined symbol: __cfi_slowpath_diag
>>> referenced by event.c
>>>               pkg.lto.event.o:(cleanup_handler.52c52c1eb832dce3a09137c36f3b0e8a.cfi)
>>> referenced by ucl_emitter_utils.c
>>>               /wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg/pkg.lto.libpkg_flat.a(ucl_emitter_utils.o at 3229650).o:(ucl_elt_string_write_json.cfi)
>>> referenced by ucl_emitter_utils.c
>>>               /wrkdirs/usr/ports/ports-mgmt/pkg/work/pkg-1.21.2/libpkg/pkg.lto.libpkg_flat.a(ucl_emitter_utils.o at 3229650).o:(ucl_elt_string_write_json.cfi)
>>> referenced 3030 more times
cc: error: linker command failed with exit code 1 (use -v to see invocation)

LDFLAGS is properly passed

https://github.com/freebsd/pkg/blob/094472054da46c966f4aaf77f8e3f683b8e7f74e/src/Makefile.autosetup#L98

I don't know why throught ports it does not find its way.

Best regards, Bapt

bapt avatar May 21 '24 13:05 bapt

As far as I can see pkg passes properly the LDFLAGS when linking, maybe a ports framework bug, but not a pkg one

bapt avatar Jul 01 '24 11:07 bapt