Bug 270740

Summary: devel/cargo-c: Generated pkg-config files have broken Libs.private definitions
Product: Ports & Packages Reporter: Daniel Engberg <diizzy>
Component: Individual Port(s)Assignee: Jan Beich <jbeich>
Status: New ---    
Severity: Affects Only Me Flags: jbeich: maintainer-feedback+
Priority: ---    
Version: Latest   
Hardware: Any   
OS: Any   
See Also: https://github.com/lu-zero/cargo-c/issues/247

Description Daniel Engberg freebsd_committer freebsd_triage 2023-04-10 14:47:50 UTC
A lot of non related libraries gets defined...

audio/lewton:
Libs.private:  -lexecinfo -lpthread -lgcc_s -lc -lm -lrt -lpthread -lrt -lutil -lexecinfo -lkvm -lmemstat -lkvm -lutil -lprocstat -lrt -ldevstat

graphics/libimagequant:
Libs.private:  -lrt -lutil -lexecinfo -lkvm -lmemstat -lkvm -lutil -lprocstat -lrt -ldevstat -lexecinfo -lpthread -lgcc_s -lc -lm -lrt -lpthread -lrt -lutil -lexecinfo -lkvm -lmemstat -lkvm -lutil -lprocstat -lrt -ldevstat

etc
Comment 1 Daniel Engberg freebsd_committer freebsd_triage 2023-04-10 15:03:59 UTC
Looking this seems to "leak" from libc crate?
Comment 2 Jan Beich freebsd_committer freebsd_triage 2023-04-10 15:14:21 UTC
Only -lgcc_s (see upstream issue) breaks static linking.

$ cc a.c -static $(pkg-config -static --cflags --libs imagequant | sed 's/gcc_s/gcc/')
$ file ./a.out
./a.out: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically linked, for FreeBSD 14.0 (1400085), FreeBSD-style, with debug_info, not stripped

$ cat a.c
#include <libimagequant.h>

int main()
{
  (void)liq_attr_create();
  return 0;
}
Comment 3 Jan Beich freebsd_committer freebsd_triage 2023-04-10 15:29:46 UTC
Overlinking isn't a problem with static libraries as ld(1) only includes object files (*.o) from archives (*.a) that satisfy references. However, object files can be large, so one may want to pass -Wl,--gc-section to trim unused stuff.
Comment 4 Jan Beich freebsd_committer freebsd_triage 2023-04-10 15:31:42 UTC
Note, to overlink a static library pass -Wl,--whole-archive