r417651 migrated bsd.ssl.mk to USES, exposing a conflict between rpath arguments provided by Uses/ncurses.mk and Uses/ssl.mk. This results in build time and runtime library linking discrepancies in certain common circumstances such as, but not limited to using ncurses from base, but openssl from ports, and a failure in at least lang/python27, reported in bug 210820 A test matrix of the difference in LDFLAG values for various ports between r417651 and r417650 (the tree before the commit) and patch has been provided for bsd.port.mk in bug 210820 that will be attached here instead.
Created attachment 173350 [details] LDFLAGS.txt Here's a list of make -V LDFLAGS output, these ports might be affected by loading ssl.mk after other USES. I just noticed there's a port security/heimdal that doesn't have ncurses in USES: r417650: -Wl,-rpath,/usr/local/lib/heimdal:/usr/local/lib -L/usr/local/lib r417651: -Wl,-rpath,/usr/local/lib/heimdal:/usr/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib LDFLAGS is empty when security/heimdal loads gssapi.mk, then it goes to line 162: https://svnweb.freebsd.org/ports/head/Mk/Uses/gssapi.mk?view=markup#l156 156 .if !empty(LDFLAGS:M-Wl,-rpath,*) 157 .for F in ${LDFLAGS:M-Wl,-rpath,*} 158 LDFLAGS:= -Wl,-rpath,${_RPATH}:${F:S/-Wl,-rpath,//} \ 159 ${LDFLAGS:N-Wl,-rpath,*} 160 .endfor 161 .else 162 LDFLAGS+= -Wl,-rpath,${_RPATH}:/usr/lib 163 .endif
Created attachment 173351 [details] bsd.port.mk.diff Here is my temporary workaround I used these days to make it load Uses/ssl.mk before other USES. I'm not proposing it as the fix. Maybe we can come up something to cacluate the load sequence automatically like rcorder(8), or the Uses/*.mk should have no dependency ordering at all ...
This change is wrong, the order into which USES are loaded should not change the outcome. From what I read, ncurses.mk is the one doing bad things here.
Please correct me if I'm wrong, I think the settings in the Uses/*.mk are appended by the order they loaded. r417650 loads bsd.ssl.mk first then Uses/ncurses.mk: % make -C /usr/ports/lang/python27 -dv -V PKGNAME 2>&1 | grep Global:LDFLAGS Global:LDFLAGS = Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} ${OPENSSL_LDFLAGS} Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} ${OPENSSL_LDFLAGS} -Wl,-rpath=${NCURSESRPATH} Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} ${OPENSSL_LDFLAGS} -Wl,-rpath=${NCURSESRPATH} -L${LOCALBASE}/lib r417651 loads Uses/ssl.mk first then Uses/ncurses.mk: % make -C /usr/ports/lang/python27 -dv -V PKGNAME 2>&1 | grep Global:LDFLAGS Global:LDFLAGS = Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} -Wl,-rpath=${NCURSESRPATH} Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} -Wl,-rpath=${NCURSESRPATH} -L${LOCALBASE}/lib Global:LDFLAGS = ${${:UTHREADS}_${:ULDFLAGS}} -Wl,-rpath=${NCURSESRPATH} -L${LOCALBASE}/lib ${OPENSSL_LDFLAGS} for the port security/heimdal, gssapi.mk is loaded first, when it sees LDFLAGS empty, LDFLAGS is set to -Wl,-rpath,${_RPATH}:/usr/lib r417650 loads bsd.ssl.mk first then Uses/gssapi.mk % make -C /usr/ports/security/heimdal -dv -V PKGNAME 2>&1 | grep Global:LDFLAGS Global:LDFLAGS = Global:LDFLAGS = ${OPENSSL_LDFLAGS} Global:LDFLAGS = -Wl,-rpath,/usr/local/lib/heimdal:/usr/local/lib Global:LDFLAGS = -Wl,-rpath,/usr/local/lib/heimdal:/usr/local/lib -L${LOCALBASE}/lib r417651 loads Uses/gssapi.mk then Uses/ssl.mk % make -C /usr/ports/security/heimdal -dv -V PKGNAME 2>&1 | grep Global:LDFLAGS Global:LDFLAGS = Global:LDFLAGS = -Wl,-rpath,${_RPATH}:/usr/lib Global:LDFLAGS = -Wl,-rpath,${_RPATH}:/usr/lib -L${LOCALBASE}/lib Global:LDFLAGS = -Wl,-rpath,${_RPATH}:/usr/lib -L${LOCALBASE}/lib ${OPENSSL_LDFLAGS}
(In reply to Fukang Chen from comment #4) > r417651 loads Uses/ssl.mk first then Uses/ncurses.mk: sorry, it should be r417651 loads Uses/ncurses.mk first then Uses/ssl.mk
Created attachment 173494 [details] patch There are three cases here: 1) USES=ncurses or USES=ncurses:base and devel/ncurses is not present: use base, no need to add rpath as there is only one libncurses.so present, in /usr/lib 2) USES=ncurses and devel/ncurses is present or USES=ncurses:port: use ports, and add rpath to LOCALBASE/lib so that the right one is picked 3) USES=ncurses:base and devel/ncurses is present fail (it would warrant using -rpath /usr/lib, but it error's out during the sanity stage)
Created attachment 173545 [details] gssapi.mk.diff Hi Mathieu, Thanks for the nucrses.mk patch. I think it should fixed all the ports that have ncurses in USES. I just tested it with lang/python27, it worked. :) gssapi.mk has a similar problem. Here are steps to reproduce it. compiling mail/fetchmail with the GSSAPI_HEIMDAL option and it uses the OpenSSL from base. # cd /usr/ports/mail/fetchmail # make BATCH=1 WITHOUT+=GSSAPI_BASE WITH+=GSSAPI_HEIMDAL DEFAULT_VERSIONS+=ssl=openssl # ldd work/stage/usr/local/bin/fetchmail | grep ssl.so libssl.so.8 => /usr/lib/libssl.so.8 (0x20188000) # readelf -d work/stage/usr/local/bin/fetchmail | grep PATH 0x0000000f RPATH Library rpath: [/usr/local/lib/heimdal:/usr/lib:/usr/local/lib] 0x0000001d RUNPATH Library runpath: [/usr/local/lib/heimdal:/usr/lib:/usr/local/lib] # make BATCH=1 WITHOUT+=GSSAPI_BASE WITH+=GSSAPI_HEIMDAL DEFAULT_VERSIONS+=ssl=openssl -V LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib/heimdal:/usr/lib -Wl,-rpath,/usr/local/lib
Mmmm, yes, gssapi.mk needs to be fixed to remove /usr/lib too. There's never a good reason for putting it in. For GSSAPI, there are two cases: 1) OpenSSL from ports is installed -> Any GSSAPI from ports, but can't have base. 2) OpenSSL from the base system -> Any GSSAPI you want
A commit references this bug: Author: mat Date: Thu Sep 8 14:12:56 UTC 2016 New revision: 421554 URL: https://svnweb.freebsd.org/changeset/ports/421554 Log: Fix ncurses to not add /usr/lib to rpath. There are three cases here: 1) USES=ncurses or USES=ncurses:base and devel/ncurses is not present: use base, no need to add rpath as there is only one libncurses.so present, in /usr/lib 2) USES=ncurses and devel/ncurses is present or USES=ncurses:port: use ports, and add rpath to LOCALBASE/lib so that the right one is picked 3) USES=ncurses:base and devel/ncurses is present fail (it would warrant using -rpath /usr/lib, but it error's out during the sanity stage) PR: 211592 Reported by: koobs (and many others) Reviewed by: bapt Sponsored by: Absolight Differential Revision: https://reviews.freebsd.org/D7459 Changes: head/Mk/Uses/ncurses.mk