Bug 221778

Summary: devel/libcfg: port passes flags from ${LDFLAGS} to the compiler driver and directly to ${LD} (invalid)
Product: Ports & Packages Reporter: Ed Maste <emaste>
Component: Individual Port(s)Assignee: Rodrigo Osorio <rodrigo>
Status: Closed FIXED    
Severity: Affects Only Me Flags: bugzilla: maintainer-feedback? (rodrigo)
Priority: ---    
Version: Latest   
Hardware: Any   
OS: Any   
Bug Depends on:    
Bug Blocks: 214864    
Attachments:
Description Flags
disable lld for devel/libcfg none

Description Ed Maste freebsd_committer freebsd_triage 2017-08-24 21:36:32 UTC
Created attachment 185730 [details]
disable lld for devel/libcfg

In general ${LDFLAGS} contains flags for the compiler driver and should be passed to the compiler driver, not directly to the linker.

libcfg tries to use it both ways, which is invalid -- in Rules.mk.in

$(LIBDYNAMICV): $(OBJECTS)
        $(LD) $(LDFLAGS) -shared -o $@ $(OBJECTS)
..
CCLD         = $(CC)
LINK         = $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@

Found while trying to link with lld as /usr/bin/ld, because lld interpreted -fstack-protector as an invalid argument:

===>  Building for libcfg-0.6.2_3
...
ar: warning: creating libcfg+.a
ld: error: unknown argument: -fstack-protector
...

Even though this appears to work with GNU ld (ld.bfd) it produces a shared object with a bogus entry:

nuc% readelf -d work/stage/usr/local/lib/libcfg+.so

Dynamic section at offset 0x92c8 contains 15 entries:
  Tag                Type                  Name/Value
 0x000000007ffffffd AUXILIARY            Auxiliary library: [stack-protector]
...
nuc%
Comment 1 Rodrigo Osorio freebsd_committer freebsd_triage 2017-12-04 17:44:12 UTC
Committed, thanks.
Comment 2 commit-hook freebsd_committer freebsd_triage 2017-12-04 17:44:45 UTC
A commit references this bug:

Author: rodrigo
Date: Mon Dec  4 17:43:55 UTC 2017
New revision: 455529
URL: https://svnweb.freebsd.org/changeset/ports/455529

Log:
  devel/libcfg: set LLD_UNSAFE

  This port passes ${LDFLAGS} to both the compiler driver and directly
  to the linker, which is not valid. Revert to using ld.bfd for now which
  produces output with a bogus entry, but does not fail to link.

  Bump portrevision.

  PR:		221778
  Submitted by:	emaste@
  Approved by:	rodrigo@ (maintainer)

Changes:
  head/devel/libcfg/Makefile